我目前正在通过 .click 事件添加一个输入,然后想要收听此输入上发生的任何按键。但是,附加的在插入后不会触发任何事件(即模糊、按键、焦点)。有没有人有什么建议?提前致谢!
$("#recipientsDiv").click(function(){
$(this).append('< input type="text" id="toInput" class="inlineBlockElement" style="border:0px none #ffffff; padding:0px; width:20px; overflow:hidden;" />')
$("#toInput").focus();
});
$("input").keypress(function(e){
var inputStr = $(this).html();
$("#inputCopier").text(inputStr);
var newWidth = $("#inputCopier").innerWidth;
$(this).css("width", newWidth);
});
$("#toInput").blur(function(){
$("#toInput").remove();
});
我也尝试过 .keyup .keydown ,但它们不起作用。