这里有一些错误。我正在尝试使用我使用 javascript 创建的 ID,但它不起作用。
$('#button').on('click', function() {
$('#here').html('<p> thank you for clicking </p>');
$('#here2').html('<input type="button" id="button2" value="click me now" />');
});
$('#button2').on('mouseover' function() {
$('#button2').css({
'background-color':'#0FF';
'width':'400px';
'height':'200px';
});
});
我认为这是可能的,但我不知道怎么做。 请教我正确的方法。
最佳答案
使用 jquery 事件验证:因为当时 DOM 已准备就绪,button2 id 不存在。所以可以这样抓:
$(document).on('mouseover','#button2', function() { // See change in this line.
$('#button2').css({
'background-color':'#0FF',
'width':'400px',
'height':'200px'
});
});
关于javascript - 我可以继续使用 javascript 创建的 ID 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45348674/