HTML大概如下:
<div class="test_div">
<button class="ok_button" id="ok_button" name="buttonCheck" style="cursor:pointer" onclick=submit(this)>確認</button>
</div>
<div class="test_div">
<button class="ok_button" id="ok_button" name="buttonCheck" style="cursor:pointer" onclick=submit(this)>確認</button>
</div>
<div class="test_div">
<button class="ok_button" id="ok_button" name="buttonCheck" style="cursor:pointer" onclick=submit(this)>確認</button>
</div>
我希望能在按下按鈕時,針對點擊的那個按鈕的div class做改變。
目前無論點擊哪個按鈕,都是改變第一個div class,
javascript如下:
function submit(Obj) {
var testDiv_Obj = document.getElementsByClassName("test_div");
for (var i = 0; i < testDiv_Obj.length; i++) {
document.getElementById("test_div").className = "new_div";
}
};
請幫幫忙~感謝~