導航:首頁 > 編程語言 > js點擊按鈕完成2次請求

js點擊按鈕完成2次請求

發布時間:2025-06-29 07:49:43

1. 為什麼我的js一開始需要點擊兩次才能觸發,之後點擊一次就可以了。麻煩幫忙解決一下

有一種情況可能是因為網頁中的某些javaScript腳本代碼往往需要在文檔載入完成後才專能夠去執行,屬否則可能導致無法獲取對象的情況,當第一次點擊時文檔才載入完畢;所以第二次點擊時才有反應。為了避免類似情況的發生,可以使用以下兩種方式:
(1).將腳本代碼放在網頁的底端,運行腳本代碼的時候,可以確保要操作的對象已經載入完成。
(2).通過window.onload來執行腳本代碼。

2. vue.js怎樣解決按鈕多次點擊重復提交

建議使用ref,給button添加註冊ref引用,然後在表單提交的時候,獲取button按鈕,使其disable置灰。

ref被用來內給元素容或子組件注冊引用信息。引用信息將會注冊在父組件的$refs對象上。如果在普通的 DOM 元素上使用,引用指向的就是 DOM 元素;如果用在子組件上,引用就指向組件。

<divid="app">
<buttonref="mybutton"type="primary"@click="save">保存</button>
</div>
<script>
newVue({
el:"#app",
data:{
},
methods:{
save(){
this.$refs.mybutton.disabled=true;
}
}
})
</script>
<style>
:disabled{
border:1pxsolid#DDD;
background-color:#F5F5F5;
color:#ACA899;
}
</style>

3. 怎麼用JS實現 按鈕功能的循環執行

用JS實現 點擊『提交』 按鈕變成 『繼續添加』同時文本框變灰且只可讀, 再次點擊 『繼續添加』 文本框變回原來可寫,按鈕變成『提交』。一直可以循環執行:
var bbb = document.getElementById('btn1');
bbb.onclick = function() {
var ttt = document.getElementById('btn1').value;
if (ttt == '提交') {
isreadonly();
changebutton1();
} else if (ttt == '繼續添加') {
readwrite();
changebutton2();
}
};

function isreadonly() {
var obj = document.getElementById("in1");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";

var obj = document.getElementById("in2");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
var obj = document.getElementById("in3");
obj.setAttribute("readOnly", true);
obj.style.backgroundColor = "#d2d2d2";
}

function readwrite() {
var obj = document.getElementById("in1");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";

var obj = document.getElementById("in2");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";

var obj = document.getElementById("in3");
obj.setAttribute("readOnly", false);
obj.style.backgroundColor = "#ffffff";
}

function changebutton1() {
document.getElementById('btn1').value = '繼續添加';

}
function changebutton2() {
document.getElementById('btn1').value = '提交';
}
應用:可將上訴代碼中的文字替換,實現其它類型的循環執行。

4. 網頁用jsp實現按鈕點擊第一下實現事件一,第二下實現事件二

<html>
<head>
<scriptsrc="/jquery.min.js"></script>
<scripttype="text/javascript">
$(document).ready(function(){
varclickNum=1;

$("button").click(function(){
switch(clickNum){
case1:
alert("事件1");
clickNum=2;
break;
case2:
alert("事件2");
clickNum=1;
break;
}
});
});
</script>
</head>
<body>
<button>按鈕</button>
</body>
</html>

5. js點擊彈出提示1,再次點擊彈出2,再次點擊彈出1

//javascript
varnum=1;
window.onload=function(){
document.getElementById("b1").onclock=function(){
alert(num);
if(num==1){
num=2;
}
else{
num=1
}
}
}
<!--html-->
<buttonid="b1">單擊彈窗</button>

6. js實現間隔相同時間自動觸發兩個按鈕的點擊事件,兩個按鈕觸發事件時間間隔一樣,然後循環

<body>
<inputtype="checkbox"id="a"/>2秒循環選中<br/>
</body>
<script>
varj=setInterval("clickTuo()",2000);//2秒鍾後調用clickTuo--初始化
functionclickTuo(){
clearInterval(j);//清理
$("#a").attr("checked","checked");
j=setInterval("clickTuo2()",2000);//2秒鍾後調用clickTuo2
};
functionclickTuo2(){
clearInterval(j);//清理
$("#a").removeAttr("checked");
j=setInterval("clickTuo()",2000);//2秒鍾後調用clickTuo
};
</script>

7. js控制按鈕的點擊次數

<script>
window.onload=function(){
vart=document.getElementById("t");
t.onclick=function(){
varcurCount=document.getElementById("t").getAttribute("count");
if(parseInt(curCount)>2){
alert("已點擊兩次")
}else{
document.getElementById("t").setAttribute("count",parseInt(curCount)+1)
}
}
}
</script>
<buttonname="t"id="btn"count='0'></button>

8. 一個按鈕 怎樣調用兩個JS事件

先寫兩個事件:
function a(){}
function b(){}
在寫一個調用這兩個:
function c(){
a();
b();
}
最後在input里調用c事件就可以了
著知識一種回辦法還有其他法子答在找找

9. JS實現滑鼠點擊一個按鈕不同次數觸發不同事件

JS實現滑鼠點擊一個按鈕不同次數觸發不同事件,什麼啊,是用語言實現嗎

閱讀全文

與js點擊按鈕完成2次請求相關的資料

熱點內容
把兩個文件合並成一個文件 瀏覽:77
app下載時間如何顯示最新 瀏覽:71
網路圖標顯示異常 瀏覽:37
微信視頻保存在哪個文件了 瀏覽:685
統計文件夾軟體 瀏覽:322
c找不到資產文件 瀏覽:193
可編程式控制制板有哪些 瀏覽:939
同行業數據可以從哪裡拿到 瀏覽:476
什麼app可以推薦書看 瀏覽:336
數據線有水給手機充電會怎麼樣 瀏覽:111
輻射島沒有存檔文件夾 瀏覽:603
神之墓地裝備升級 瀏覽:869
社區什麼時候會查通行大數據 瀏覽:855
html5和java哪個難 瀏覽:989
美版se版本號查詢 瀏覽:733
小蘋果手機鈴聲女生版 瀏覽:32
qq空間刪說說不用軟體 瀏覽:891
通達信編寫程序 瀏覽:513
編程貓怎麼讓人物來回走動 瀏覽:699
口袋火紅升級 瀏覽:15

友情鏈接