如何使用jquery获取指向的项目。我的意思是指向项目,如果鼠标点击正文中的某个div,我想获取该div的信息,或者单击选择框或等等..所以他们没有tchoasen由我,选定的项目都是网络中的所有html元素,只是我想要接收我点击的元素女巫的信息。使用jquery获取指向元素
2
A
回答
2
$(document.body).click(function(ev) {
$(ev.target); // is the clicked element
});
0
0
嗯,我不知道如果我理解你的问题,但你指的.html()
方法。下面的例子会在点击或悬停时弹出div的内容。
例
<div id='test'>Content of div</div>
//on click
$('#.test').click(function(){
alert($(this).html());
});
//on hover
$('#.test').hover(function(){
alert($(this).html());
});
0
假设你有一个div
ID为 '测试' 你的body
元素中。通过jQuery注册事件如下:
$("div#test").click(function(event){
alert(event.target);
/*here event is the object fired, and target is the Div element i.e. source or you can use 'this' to refer to Div element*/
alert(this);
// Here 'event.target' and 'this' will give the same Div element.
});
相关问题
- 1. 如何使用JQuery获取包含指定文本的元素?
- 2. 使用jQuery获取DOM元素名称
- 3. Jquery - 使用find()获取元素的ID
- 4. 使用jQuery获取HTML元素
- 5. 获取列表元素和使用jQuery
- 6. 使用jquery获取元素值
- 7. 使用jQuery获取元素位置
- 8. 获取元素使用jQuery。对()
- 9. 使用jQuery从元素获取文本
- 10. 获取DOM元素使用jQuery
- 11. 使用jquery获取html元素的ID
- 12. 使用jquery获取元素id
- 13. Array获取元素向后
- 14. Python:获取指向列表元素的指针
- 15. 如何使用jQuery获取父元素的同级元素
- 16. 使用jQuery获取下一个或带有元素的元素
- 17. 使用jQuery获取元素的所有直接子元素
- 18. 使用jQuery获取每个元素的子元素的长度
- 19. 获取DOME元素的jQuery元素
- 20. 获取jQuery元素值
- 21. 从元素Jquery获取JSON?
- 22. jQuery按类获取元素
- 23. jQuery - 获取邻域元素
- 24. jquery获取子元素值
- 25. 获取对象元素jquery
- 26. jQuery的:获取元素
- 27. 指向元素的向量
- 28. 使用event.target获取元素
- 29. 获取使用父元素
- 30. 使用mousemove获取元素
感谢安德鲁,其实我不知道如何使用代码窗口,新的到stackoverflow – user482144 2011-05-23 07:49:31