我在我的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);
}
});
但不起任何作用..
任何帮助表示赞赏!