如何使用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獲取html元素的ID
- 3. 使用jQuery獲取HTML元素
- 4. 使用jQuery獲取元素父項
- 5. Jquery - 使用find()獲取元素的ID
- 6. 使用jQuery從元素獲取文本
- 7. 獲取DOM元素使用jQuery
- 8. Python:獲取指向列表元素的指針
- 9. 使用jQuery獲取元素的所有直接子元素
- 10. 如何使用jQuery獲取父元素的同級元素
- 11. 獲取DOME元素的jQuery元素
- 12. 從元素Jquery獲取JSON?
- 13. 獲取對象元素jquery
- 14. 獲取jQuery元素值
- 15. jquery獲取子元素值
- 16. jQuery - 獲取鄰域元素
- 17. 使用event.target獲取元素
- 18. 使用HtmlAgilityPack獲取元素
- 19. 使用Javascript - 獲取元素
- 20. 如何獲取指向元素的DOM節點,jQuery節點或選擇器?
- 21. 用Jquery獲取多個元素的值
- 22. 用jquery獲取html數組元素
- 23. Jquery - 獲取禁用的元素
- 24. jquery:從ajax調用獲取父元素
- 25. 使用jquery獲取元素的像素寬度
- 26. 使用SoapClient從PHP獲取元素使用SoapClient獲取PHP中的元素
- 27. 如何使用jquery通過指定的標籤名稱獲取父元素?
- 28. 從Angular指令中獲取html元素
- 29. 在指定位置獲取元素 - JavaScript
- 30. 在Angular指令中獲取父元素
感謝安德魯,其實我不知道如何使用代碼窗口,新的到stackoverflow – user482144 2011-05-23 07:49:31