jQuery重新加载DOM? [英] jQuery reload the DOM?
问题描述
我的问题是新的创建的表单不响应任何jQuery命令。这是我现在提供的表单的代码。
$(#savenewlang)。click(function e){
console.log(savenewlang已被点击);
});
所以当他们点击提交按钮但是没有运行时,应该只是console.log。 >
任何想法如何重新加载DOM或分配一个正确触发的实际事件?
$(#container)。on('click','#savenewlang',function(e){
console.log(savenewlang has been clicked );
});
这里 #container
指向父元素的 #savenewlang
在页面加载时属于DOM。
要指定此事件 .on()
您需要 三个参数
.on(eventName,target,callback);
但是对于普通绑定,只需要 两个参数 strong>
.on(eventName,callback);
详细了解 .on()
剩余
将所有代码放在
code> $(document).ready(function(){
});
简而言之
code> $(function(){
});
I have a page that has a button on it. When the user clicks the button it dynamically render's a form (ie it's not just showing a hidden form.. it's completely creating it using jQuery).
My issue is the newly created form doesn't respond to any jQuery commands. This is the code I have for the rendered form at the moment.
$("#savenewlang").click(function(e) {
console.log("savenewlang has been clicked");
});
So it should just console.log when they click the submit button but it's not running.
Any idea how to reload the DOM or assign that an actual event that correctly fires?
$("#container").on('click', '#savenewlang', function(e) {
console.log("savenewlang has been clicked");
});
Here #container
points to a parent element of #savenewlang
that belongs to DOM at page load.
To specify this event .on()
you need three arguments
.on(eventName, target, callback);
But for ordinary binding it only needs two arguments
.on(eventName, callback);
Read more about .on()
Remainder
Put all of your code within
$(document).ready(function() {
});
in short
$(function() {
});
这篇关于jQuery重新加载DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!