1 不知道為什么onclick事件不起作用了。。。
html
<p id="leftSide_xia" style="display:none;text-align:center;">
<ul class="" style="margin-top:10px;">
<!-- <li style="height:52px;cursor:pointer;" onclick="openIllegalPage('isOnList')">wwwwwww</li>-->
<p onclick="openIllegalPage('websiteList')"><img name="leftSide_xia_menu" onclick="openIllegalPage('websiteList')" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li onclick="openIllegalPage('websiteList')" style="height:30px;cursor:pointer;" ><a onclick="openIllegalPage('websiteList')" style="margin-right:25%;">wwww覽</a> </li><hr style="border:0;background-color:rgb(8,30,44);height:2px;margin-top:0px;width:90%;"/>
</p>
<p onclick="openIllegalPage('websiteNameList')"><img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li style="height:30px;cursor:pointer;" ><a style="margin-right:25%;">wwwwwwww</a></li><hr style="border:0;background-color:rgb(8,30,44);height:1px;margin-top:0px ;width:90%;"/>
</p>
<p>
<img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li style="height:30px;cursor:pointer;" onclick="openIllegalPage('recordNumberList')"><a style="margin-right:28%;">wwwwwwww/a></li></li><hr style="border:0;background-color:rgb(8,30,44);height:1px;margin-top:0px ;width:90%;"/>
</p>
<p><img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li style="height:30px;cursor:pointer;" onclick="openIllegalPage('unitNameList')"><a style="margin-right:25%;">wwwwww</a></li><hr style="border:0;background-color:rgb(8,30,44);height:1px;margin-top:0px ;width:90%;"/>
</p>
<p><img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li style="height:30px;cursor:pointer;" onclick="openIllegalPage('contactNameList')"><a style="margin-right:28%;">wwwwwwww</a></li><hr style="border:0;background-color:rgb(8,30,44);height:2px;margin-top:0px ;width:90%;"/>
</p>
<p><img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li style="height:30px;cursor:pointer;" onclick="openIllegalPage('contactNameList')"><a style="margin-right:20%;">wwwwww</a></li><hr style="border:0;background-color:rgb(8,30,44);height:1px;margin-top:0px ;width:90%;"/>
</p>
<p><img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;"/><li style="height:30px;cursor:pointer;" onclick="openIllegalPage('contactTelephoneList')"><a style="margin-right:10%;">wwwwwww</a></li><hr style="border:0;background-color:rgb(8,30,44);height:1px;margin-top:0px ;width:90%;"/>
</p>
</ul>
</p>
業(yè)精于勤,荒于嬉;行成于思,毀于隨。
<p onclick="openIllegalPage('websiteList')">
function openIllegalPage(ppp,pageName){
if(pageName=="websiteList")
}
注意一下參數(shù)
如果運(yùn)行沒有出錯(cuò)的話是會(huì)執(zhí)行呢,你可以在openIllegalPage這方法alert() 看一下。我剛復(fù)制你代碼看了一下是可以執(zhí)行這函數(shù)的
你這養(yǎng)寫多個(gè)點(diǎn)擊事件它會(huì)沖突的,比如你點(diǎn)里面的元素,外面的元素都會(huì)執(zhí)行。
我優(yōu)化了一下,你可以參考一下:
html:
<ul class="" style="margin-top:10px;">
<!-- <li style="height:52px;cursor:pointer;" onclick="openIllegalPage('isOnList')">網(wǎng)站在線監(jiān)察</li>-->
<p>
<img name="leftSide_xia_menu" src="/images/frame/icon_a.png" style="margin-left:35px;float:left;margin-top:6px;" />
<li style="height:30px;cursor:pointer;">
<a style="margin-right:25%;">不規(guī)范網(wǎng)站總覽</a>
</li>
<hr style="border:0;background-color:rgb(8,30,44);height:2px;margin-top:0px;width:90%;" />
</p>
</ul>
js:
window.onload = function() {
var onUl = document.querySelector('ul');
onUl.onclick = function(e) {
/**
* e.target為事件源(也就是你點(diǎn)哪個(gè)就是哪個(gè))
* 這時(shí)候你點(diǎn)哪個(gè)就是拿到哪個(gè)的節(jié)點(diǎn)了,
* 然后根據(jù)(e.target.tagName)判斷
*/
console.log(e.target.tagName);
}
}
你在p上添加了點(diǎn)擊事件,然后你還在p下的img添加點(diǎn)擊事件,你這樣就造成了參數(shù)的重復(fù),要么你就加在img上就行了,手機(jī)端的不想敲代碼。