search

Home  >  Q&A  >  body text

javascript - onclick event click not working

1 I don’t know why the onclick event doesn’t work. . .
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>
                


迷茫迷茫2788 days ago1088

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-06-06 09:54:06

    <p onclick="openIllegalPage('websiteList')">

    function openIllegalPage(ppp,pageName){
        if(pageName=="websiteList")
    }

    Pay attention to the parameters

    reply
    0
  • 高洛峰

    高洛峰2017-06-06 09:54:06

    If there are no errors during operation, it will be executed. You can take a look at the alert() method of openIllegalPage. I just copied your code and saw that it can execute this function. If you write multiple click events, it will conflict. For example, if you click on an element inside, all elements outside will be executed.
    I optimized it, you can refer to it:
    html:
    <ul class="" style="margin-top:10px;">

            <!-- <li  style="height:52px;cursor:pointer;" onclick="openIllegalPage('isOnList')">网站在线监察</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%;">不规范网站总览</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为事件源(也就是你点哪个就是哪个)
                     * 这时候你点哪个就是拿到哪个的节点了,
                     * 然后根据(e.target.tagName)判断
                     */
                    console.log(e.target.tagName);
                }
    
            }

    reply
    0
  • 迷茫

    迷茫2017-06-06 09:54:06

    You added a click event to p, and then you also added a click event to the img under p. This will cause duplication of parameters, or you can just add it to the img. You don’t want to type code on the mobile phone.

    reply
    0
  • PHP中文网

    PHP中文网2017-06-06 09:54:06

    Breakpoint debugging is really not possible

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-06 09:54:06

    The code can’t bear to be looked at

    reply
    0
  • Cancelreply