JQuery的 - 点击事件添加到LI或SPAN元素呢? [英] JQuery - add click event to LI or SPAN elements?
本文介绍了JQuery的 - 点击事件添加到LI或SPAN元素呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一个click事件添加到LI元素,但它不是在页面射击。我的页面标记如下:
I am trying to add a click event to a LI element but it is not firing in the page. My page markup looks like:
<div id="Navigation">
<ul>
<li class="navPrevNext inactive">|< First Page</li>
<li class="navPrevNext inactive">< Prev Page</li>
<li class="navIndex selected" title="0 ">1</li>
<li class="navIndex notselected" title="1 ">2</li>
<li class="navIndex notselected" title="2 ">3</li>
<li class="navPrevNext active" title="1">Next Page ></li>
<li class="navPrevNext active" title="2">Last Page >|</li>
</ul>
</div>
在我的JS code我有:
And in my JS code I have:
$("#Navigation li").live('click', function(e) { e.preventDefault; this.blur(); return updateNavigation($(this).attr('title')); });
有什么想法?
TIA
推荐答案
您确认您已经jQuery的1.3包含在code?对我来说,下面的工作正常(直接复制并从你的问题粘贴),当我点击任何LIS的:
You sure you have jquery 1.3 included in your code? The following works fine (direct copy and paste from your question) for me when I click on any of the LIs:
<html>
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
function updateNavigation(title) {
alert(title);
}
$("#Navigation li").live('click', function(e) {
e.preventDefault;
this.blur();
return updateNavigation($(this).attr('title'));
});
</script>
</head>
<body>
<div id="Navigation">
<ul>
<li class="navPrevNext inactive">|< First Page</li>
<li class="navPrevNext inactive">< Prev Page</li>
<li class="navIndex selected" title="0 ">1</li>
<li class="navIndex notselected" title="1 ">2</li>
<li class="navIndex notselected" title="2 ">3</li>
<li class="navPrevNext active" title="1">Next Page ></li>
<li class="navPrevNext active" title="2">Last Page >|</li>
</ul>
</div>
</body>
</html>
你确定你的updateNavigation功能工作的权利?也许它被触发,但内部的东西是错误的...
Are you sure your updateNavigation function is working right? Maybe it's being triggered but something is wrong within it...
这篇关于JQuery的 - 点击事件添加到LI或SPAN元素呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文