-3
我得到5個按鈕,每次點擊都會觸發事件來實時生成新的不同按鈕。 問題是如何在2秒內模擬每個按鈕單擊事件。 像其他語言,使用javascript:模擬點擊每個按鈕
thread.sleep(2000);
//將延遲2秒
在JavaScript中,這裏是一些方向Arguments.callee is deprecated - what should be used instead?
的setTimeout(函數(){... 的setTimeout(arguments.callee的, 100); },100); 另一個方向是jquery中的delay()函數
但是它可以觸發生成按鈕事件嗎?
$(document).ready(function() {
timer();
});
function timer() {
setTimeout(function() {
setTimeout(arguments.callee, 2000);
}, 2000);
};
function addBtn(btn) {
$("#p2").text(btn.value) // btn.value;
var count = Math.round((Math.random() * 2 * 1000)/1000, 0) + 1;
console.log(count);
$(".addbtn").remove();
for (i = 0; i < count; i++) {
$("#d2").append("<input class='addbtn' type='button' style='width:100px;color:green' value='subBtn" + btn.value + "_" + (i + 1) + "'/>")
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="d1">
<input id="btn1" type="button" onclick="addBtn(this)" style="width:100px;color:green" value="1" />
<input id="btn2" type="button" onclick="addBtn(this)" style="width:100px;color:green" value="2" />
<input id="btn3" type="button" onclick="addBtn(this)" style="width:100px;color:green" value="3" />
</div>
<div id="d2">
</div>
謝謝,你能幫助更新問題嗎? – MaxJ