2017-04-08 33 views
-1

如果可以在html中只使用一個div或id使用javascript代碼,但此javascript代碼不會影響頁面上的另一個div或id我嘗試此方法但不工作只能在一個html對象div或id中使用javascript

function deposit() { 
 
    DEPOSIT = true; \t \t \t 
 
} 
 
function withdraw(){ 
 
    DEPOSIT = false; \t 
 
    $(".norobots").slideUp(); 
 
    loadLeft(); 
 
} 
 
$(function(){ 
 
    $('div[onload]').trigger('onload'); 
 
}); 
 
function showConfirm() { 
 
    $("#confirmModal").modal("show"); 
 
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="col-md-6" id="withdraw" onload="withdraw();"> 
 

 
</div> 
 
<div class="col-md-6" id="deposit" onload="deposit();"> 
 

 
</div>

回答

0

是的,當然!有可能使用JavaScript(在你的情況下,jQuery)來操作只有具有特定ID的div。

jquery具有選擇器(與CSS具有相同的語法)來選擇名稱,CSS類和ID中的div。這取決於你創建一個div並給它一個id。但是您需要知道您的JavaScript代碼存在於整個頁面中,並且可能會影響具有相同ID,類或名稱的其他div。

相關問題