问题是IE没有在数组中找到带链接的对象?它可以在任何其他浏览器中使用,但不能在IE中使用。我尝试了一切。请帮忙。
<html>
<head>
<title>test</title>
</head>
<body>
<div class="tminheight">
<div class="content">
<h2><a href="/folder/link1">link1</a></h2> <!-- links that need to be cached -->
</div>
<div class="content">
<h2><a href="/folder/link4">link4</a></h2> <!-- links that need to be cached -->
</div>
</div>
<div>
<ul>
<li><a href="/somewhere1"> </a></li> <!-- links that need to be clicked -->
<li><a href="/somewhere2"> </a></li> <!-- links that need to be clicked -->
<li><a href="/somewhere3"> </a></li> <!-- links that need to be clicked -->
</ul>
</div>
</body>
</html>
这是JavaScript的代码
<script type="text/javascript">
$(document).ready(function(){
//Array with a links that need to be compared
var lisNo = {0:'/folder/link1',1:'/folder/link2',2:'/folder/link3'};
$.each(lisNo, function(q, w) {
// Caching the links from array
$("div.tminheight div.content h2 a[href$='"+w+"']").live('click', function(event) {
event.preventDefault();
//Trigger a click on a link in list by ID from Array
$('ul li:eq('+q+') a').trigger('click');
return false;
});
});
});
</script>
答案 0 :(得分:0)
代码有效,触发器不会:http://jsfiddle.net/mplungjan/4vHL9/
为什么不从其他链接复制href呢?
$("someHiddenDiv").load( $('ul li:eq('+q+') a').attr("href"))
您的评论是错误的吗?您还想在单击顶部链接时单击LI中的链接?
答案 1 :(得分:0)
切换报价:
$('div.tminheight div.content h2 a[href$="'+w+'"]').live('click', function(event) {