2017-02-12 71 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

這很好,爲我工作。非常感謝你。 :) –