在 <div> 中使用..
<li onclick="goods_spec.set_style(this,1,<?php echo $k.",".$v['info_id'];?>)" id="specinfo<?php echo $v['info_id'];?>" ></li>
按钮自动触发onclick事件,可以使用定时器setInterval()方法实现。默认已点击,可以在加载网页的时候使用onload方法实现一次点击。
以下例子,实现网页打开时默认弹出弹窗,在关闭弹窗后,每2秒钟自动点击一次弹出弹窗,完整的代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>自动点击例子</title>
</head>
<body onload="alert('这是默认点击弹窗')">
<script type="text/javascript">
setInterval(function() {
if(document.all) {
document.getElementById("buttonid").click();
}
else {
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
document.getElementById("buttonid").dispatchEvent(e);
}
}, 2000);
</script>
<input id="buttonid" type="button" value="按钮" onclick="alert('这是自动点击弹窗')" />
<style type="text/css">
input{background:red;color:#fff;padding:10px;margin:20px;}
</style>
</body>
</html>
运行代码后,效果如下:
一、打开网页,默认点击,如下图
二、每隔2秒钟,自动点击一次,如下图:
扩展资料:
定时器setInterval()方法实现不间断点击,使用settimeout()方法可以实现一次点击后停止自动点击
完整代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>自动点击例子</title>
</head>
<body onload="alert('这是默认点击弹窗')">
<script type="text/javascript">
settimeout(function() {
if(document.all) {
document.getElementById("buttonid").click();
}
else {
var e = document.createEvent("MouseEvents");
e.initEvent("click", true, true);
document.getElementById("buttonid").dispatchEvent(e);
}
}, 2000);
</script>
<input id="buttonid" type="button" value="按钮" onclick="alert('这是自动点击弹窗')" />
<style type="text/css">
input{background:red;color:#fff;padding:10px;margin:20px;}
</style>
</body>
</html>
谢谢您的回复 请问. 这样.. )" id="specinfo" >
在 中有没有 更简单单的方式?
我不会 php
谢谢您的回复 请问. 这样.. )" id="specinfo" >
在 中有没有 更简单单的方式?
PHP我也不懂,你是说点击事件么?可以用js做
点击触发click
function show() {
alert('click被触发!');
}
document.getElementById('div1').click();
谢谢. 比如说 文字 这样的 有更简单的 默认自动点击的吗?
追答目前没发现有,
文字
document.getElementById('a1').click();
这已经很简单了....