本文实例讲述了jQuery获取单击节点对象的方法。分享给大家供大家参考,具体如下:
event.target属性:
<script language="JavaScript" type="text/javascript">
$("document").ready(function () {
$(".menu").bind("click", function (event) {
var clickedNode = event.target;
var NodeType = event.target.nodeName;
if (NodeType == "DIV") {
return;
}
if (NodeType == "INPUT") {
var DivId = clickedNode;
$(".menu").removeClass('addborder');
$(DivId.parentNode).addClass('addborder');
}
if (NodeType == "A") {
var DivId = clickedNode;
$(".menu").removeClass('addborder');
$(DivId.parentNode.parentNode).addClass('addborder');
}
})
</script>
解释: 其中event.target 即为触发单击事件的对象 (有可能是容器内部的某个控件)
[b]PS:这里再为大家推荐几款代码格式化、美化工具,相信大家在以后的开发过程中会用得到:[/b]
[b]在线JavaScript代码美化、格式化工具:
[/b][url=http://tools.jb51.net/code/js]http://tools.jb51.net/code/js[/url]
[b]JavaScript压缩/格式化/加密工具:
[/b][url=http://tools.jb51.net/code/jscompress]http://tools.jb51.net/code/jscompress[/url]
[b]C语言风格/HTML/CSS/json代码格式化美化工具:
[/b][url=http://tools.jb51.net/code/ccode_html_css_json]http://tools.jb51.net/code/ccode_html_css_json[/url]
[b]XML代码在线格式化美化工具:
[/b][url=http://tools.jb51.net/code/xmlcodeformat]http://tools.jb51.net/code/xmlcodeformat[/url]
[b]json代码在线格式化/美化/压缩/编辑/转换工具:
[/b][url=http://tools.jb51.net/code/jsoncodeformat]http://tools.jb51.net/code/jsoncodeformat[/url]
[b]在线JSON代码检验、检验、美化、格式化工具:
[/b][url=http://tools.jb51.net/code/json]http://tools.jb51.net/code/json[/url]
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/200.htm]jQuery常用插件及用法总结[/url]》、《[url=http://www.1sucai.cn/Special/93.htm]jquery中Ajax用法总结[/url]》、《[url=http://www.1sucai.cn/Special/539.htm]jQuery表格(table)操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/497.htm]jQuery拖拽特效与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/451.htm]jQuery扩展技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/430.htm]jQuery常见经典特效汇总[/url]》、《[url=http://www.1sucai.cn/Special/104.htm]jQuery动画与特效用法总结[/url]》及《[url=http://www.1sucai.cn/Special/75.htm]jquery选择器用法总结[/url]》
希望本文所述对大家jQuery程序设计有所帮助。