忽略底层元素的单击事件

时间:2013-06-14 09:30:20

标签: javascript html onclick

这是我的代码

<tr class="rood hoverpointer" onclick="javscript:submenu('PR1301301065','KN_KABEL', event);">
    <td>PR1301301065</td>
    <td class="statusbalk">
        <img class="active" src="img/stop-big.png" alt="Niet gestart" onclick="javascript:setStatus('PR1301301065', 'KN_KABEL',1,this)">
        <img src="img/play-big.png" alt="Gestart" onclick="javascript:setStatus('PR1301301065', 'KN_KABEL',2,this)">
        <img src="img/pause-big.png" alt="Gestopt" onclick="javascript:setStatus('PR1301301065', 'KN_KABEL',3,this)">
        <img src="img/done-big.png" alt="Afgerond" onclick="javascript:setStatus('PR1301301065', 'KN_KABEL',4,this)">
    </td>
</tr>

关于onclick-events的全部内容。当我点击我的表格行时,会触发函数submenu()。这很好。但是当我点击我的一张图片时,setStatus()submenu()都会因为底层的桌子而被触发。如何忽略我的tablerow功能并仅触发setStatus()

2 个答案:

答案 0 :(得分:0)

当您调用子菜单时,您可以尝试切换以检查单击了哪个按钮。您 只需要调用其他按钮你的子菜单功能传递他们的id

 <tr class="rood hoverpointer" id="trRood" onclick="javscript:submenu('PR1301301065','KN_KABEL', event,'trRood');">
            <td>PR1301301065</td>
            <td class="statusbalk">
                <img class="active" id="img1" src="img/stop-big.png" alt="Niet gestart" onclick="javascript:submenu('PR1301301065', 'KN_KABEL',1,this,'img1')">
                <img src="img/play-big.png" id="img2" alt="Gestart" onclick="javascript:submenu('PR1301301065', 'KN_KABEL',2,this,'img2')">
                <img src="img/pause-big.png" id="img3" alt="Gestopt" onclick="javascript:submenu('PR1301301065', 'KN_KABEL',3,this,'img3')">
                <img src="img/done-big.png" id="img4" alt="Afgerond" onclick="javascript:submenu('PR1301301065', 'KN_KABEL',4,this,'img4')">
            </td>
        </tr>


function submenu(...,...,id){

switch(id)

case "trRood":
//do your normally function
break;

case "img1":
//Call your setStatus function
break;

case "img2":
//Call your setStatus function
break;

case "img3":
//Call your setStatus function
break;

case "img4":
//Call your setStatus function
break;
}

就是这样的。

答案 1 :(得分:0)

是的,您可以将HTML中的img标记更改为..

    <img src="img/done-big.png" alt="Afgerond" onclick="javascript:setStatus(event,'PR1301301065', 'KN_KABEL',4,this)">

在javascript中添加setStatus函数中的event.stopPropogation()。