[英]Javascript / JQuery "onclick" not working
Why isn't this working?为什么这不起作用? I can't figure it out.
我想不通。
In case it matters, the HTML was injected into a div using jQuery's .append() method.以防万一,HTML 使用 jQuery 的 .append() 方法注入到 div 中。
Thanks!谢谢!
$(document).ready( function() {
$("#changeInfo").on("click", function() {
$("#changeInfo").replaceWith('<div id=changeInfo"><div id="changeInfoTrue">Changing login information: </div>');
$("#changeInfoTrue").append('<br><b>Username: <input type="text" name="newUsername" onkeypress = "checkLength()" id="newUsername" /><br> Password: <input type="password" name="newPassword" id="newPassword" onkeypress = "checkLength()" /></b> <input type="button" onclick="buttonPress();" value="Go!" id="goButton" /></div>');
});
function buttonPress() {
$("#changeInfo").replaceWith('Your login information has been reset.');
}
});
Add Jquery Libery添加 Jquery Libery
Jquery Function jQuery 函数
$(document).ready( function() {
$("#changeInfo").on("click", function() {
$("#changeInfo").replaceWith('<div id=changeInfo"><div id="changeInfoTrue">Changing login information: </div>');
$("#changeInfoTrue").append('<br><b>Username: <input type="text" name="newUsername" onkeypress = "checkLength()" id="newUsername" /><br> Password: <input type="password" name="newPassword" id="newPassword" onkeypress = "checkLength()" /></b> <input type="button" onclick="buttonPress();" value="Go!" id="goButton" /></div>');
});
function buttonPress() {
$("#changeInfo").replaceWith('Your login information has been reset.');
}
});
HTML Code HTML代码
<div class="" id="changeInfo">Click here</div
Demo Link : https://jsfiddle.net/tw79mvau/1/演示链接: https : //jsfiddle.net/tw79mvau/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.