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实现鼠标点击一个按钮不同次数触发不同事件,什么啊,是用语言实现吗