Ric*_*ich 2 javascript jquery dom
所以基本上我要做的是应用一次单击事件,然后使用event.target确定所点击的内容.在确定点击了什么之后,我可以使用它来操纵DOM.下面是我能给我一些有用的东西,但它并没有给我'正是我点击的'.
$("body").click(function(event) {
alert(event.target.nodeName); // Alerts the type of element you clicked on, but doesn't return anything 'usable' to manipulate the DOM
});
对于jQuery,$(event.target)将为您提供包含所单击元素的jQuery对象.然后你可以操纵你的心灵内容.
我看到你将click()事件绑定到$('body') So所以当你单击文档的主体时,click会e.target被身体触发.您可能希望将该click事件侦听器附加到更具体的元素,请参阅:http://jsfiddle.net/nn4sJ/8/ 作为示例
| 归档时间: |
|
| 查看次数: |
434 次 |
| 最近记录: |