我在我的html文件中輸入了一個輸入(屬性id
是:imgName
)。將輸入值輸入到html,而不是dom
當用戶輸入一些文本到這個輸入時,它被插入到DOM中。
我希望它被插入到html中。
,所以我嘗試做這件事情:
$(document).keydown(function (e) {
if (e.target.id == "imgName") {
// get the char and create text node
var text = document.createTextNode(String.fromCharCode(e.which));
// insert it to the input
e.target.appendChild(text);
}
});
但不起任何作用..
任何幫助表示讚賞!