关于如何获取onKeyUp的值有很多问题,但是我也想传递onKeyUp形式的ID。我尝试了类似的方法,但它告诉我getId没有定义。
function getId(x){
$('.not').append(x);
}
var word = 'HELP';
$('.why').html("<form class='questions'><input type='text' id='"+word+"'
name='"+word+"' onkeyup='getId("+word+")'></form> ");
http://jsfiddle.net/evs3A/
也放像
"+variable+"
这样的坏习惯,因为我经常使用它;)?感谢你。 最佳答案
使用jQuery连接事件并完全避免问题。尝试这个:
var word = 'HELP';
$('.why').html("<form class='questions'><input type='text' id='" + word + "'
name='" + word + "'></form> ");
$('.questions input').on('keyup', function(e) {
$('.not').append(this.id);
});
Example fiddle