2017-02-12 64 views
0

我的代码如下禁用HTML的标签ancher:如何通过让孩子DIV ID

<a onmouseup="some operation" class="buttonBarButtonContainer" title=""> 
<div name="buttonBarButton_Save" id="manualDeductionSaveButtonDisable" class="buttonBarButton"> 
    <table style="height:20px;" cellspacing="0" cellpadding="0" border="0"> 
     <tbody> 
      <tr> 
       <td nowrap="true"> 
        <button class="noTransformButton ico_tb-save"></button> 
       </td> 
      </tr> 
     </tbody> 
    </table> 
</div> 

这里我只有DIV ID,我想禁用父锚标记。我能怎么做?我只能使用JavaScript,甚至没有jQuery?

回答

2

根据下面的代码使用parentElement.removeAttribute('onmouseup')。一定要放的JavaScript页面的底部(我改变“一些操作”,以警示,让您可以注释掉JavaScript来验证它禁用锚警报时取消注释):

<a onmouseup="alert('hi');" class="buttonBarButtonContainer" title=""> 
 
    <div name="buttonBarButton_Save" id="manualDeductionSaveButtonDisable" class="buttonBarButton"> 
 
     <table style="height:20px;" cellspacing="0" cellpadding="0" border="0"> 
 
      <tbody> 
 
       <tr> 
 
        <td nowrap="true"> 
 
         <button class="noTransformButton ico_tb-save">Test</button> 
 
        </td> 
 
       </tr> 
 
      </tbody> 
 
     </table> 
 
    </div> 
 
</a> 
 
<script type="text/javascript"> 
 
    document.getElementById("manualDeductionSaveButtonDisable").parentElement.removeAttribute('onmouseup'); 
 
</script>

+0

这很好,为我工作。非常感谢你。 :) –