this is my first question on stack,i am not good at English,sorry for that.
my code can't stop jumping when i click the div. list is a div contains some details. my js:
function clickList(e)
{
var listAll=e.parentNode.childNodes;
var list=listAll[1];
console.log(list);
if (list.style.display == "none")
{
list.style.display = "block";
}
else
{
list.style.display = "none";
}
e.stopPropagation();
}
my html:
<a href="an address">
<div class="pull-right" onclick="clickList(this)">
<i class="iconfont"></i>
</div>
</a>
答案 0 :(得分:0)
当您停止事件传播时,您可以在href而不是地址中使用javascript:void(),如下所示:
<a href="javascript:void(0);">
<div class="pull-right" onclick="clickList(this)">
<i class="iconfont"></i>
</div>
</a>
同时删除e.stopPropagation();在clickList中,因为这将是div对象而不是事件对象。