0

我在 Jquery 工作..因为我是 JQuery 的新手。我怀疑我已经在该 DIv 中创建了一个 DIV,我有一个标签和一个文本框..我想要做的是点击那个 Generated Div,我需要显示一些现有值...但是当我单击我的 DIv 时,我会保持警报以检查单击事件是否有效。但是该单击不起作用...所以,请建议不允许新创建的 Div 事件单击? ???我的代码是,

     $("<div id=field></div>").appendTo("#displayPanel");
   $("<label id=labelstr>untitled1</label>").appendTo("#displayPanel #field");
   $("<input id=inputstr type= 'text' ></input>").appendTo("#displayPanel #field");

 $("#displayPanel #field").click(function (){alert("div clicked");});
4

2 回答 2

2

没有什么可以阻止新的 div 元素被点击。事实上,我会建议页面上的其他内容阻止它工作(可能是重复的 ID?)

您的代码在隔离时工作得很好。

于 2009-06-01T11:23:56.117 回答
1

You want the jQuery live function

It allows you to add events to elements that are loaded after the DOM finishes loading.

于 2009-06-05T02:28:38.593 回答