直接(隱式)呼叫(多個)頁面中的按鈕
阿新 • • 發佈:2019-01-05
<button type="button" name="addLine" class="btn btn-xs btn-success" onclick="test();">儲存</button> <button type="button" name="addLine" id="addline1" class="btn btn-xs btn-success" onclick="test2();">addline1</button> <button type="button" class="btn btn-xs btn-success" onclick="saveAll();">新增測試</button>
function test(){ alert(1); // var btns = document.getElementById("addline1"); // alert(btns); // btns.PerformClick; } function test2(){ alert('2'); alert(2); } function saveAll(){ var btns = document.getElementsByName("addLine"); for (var i=0;i<btns.length;i++){ btns[i].click(); //btns.PerformClick; 這個也行 } }