如果等于大于5,则使用Javascript
Javascript if equals higher than 5
所以我有一个计数器设置,如果计数超过5,我想让它自动点击报告按钮,这就是我目前所拥有的,但它似乎不起作用。
if(counter > 5){
document.getElementById("report-post-submit").click();
}
有人知道为什么它不起作用吗?
更新为完整代码:
var counter = 0
var timer;
function countUP () {
counter = counter + 1;//increment the counter by 1
//display the new value in the div
document.getElementById("timer_container").innerHTML = counter;
}
if(counter > '5'){
document.getElementById("wp-report-post-submit").click();
}
<body onload='timer=setInterval("countUP()", 1000 );'>
<div id="timer_container">0</div>
<a class="report-post-button" id="report-post-submit"><?php _e("Send Report"); ?></a>
你做错了。
检查注释行:
var counter = 0
var timer;
function countUP () {
// set onclick event if it's not appended to the element:
// document.getElementById("report-post-submit").onclick = function(){
// doStuff('Stuff done!');
// }
//increment the counter by 1
counter++;
//display the new value in the div
document.getElementById("timer_container").innerHTML = counter;
// Move this into 'countUP' function, to check counter while counting (not on page load time):
if(counter > 5){
// trigger click event applied to the button:
// document.getElementById("report-post-submit").onclick();
// or simply call the method right here:
doStuff('Stuff done!');
}
}
function doStuff(txt){
// your function to be fired on click or when counter gets more than 5:
alert(txt);
// reset counter after the stuff is done:
counter = 0;
// or clear the interval:
// clearInterval(timer);
}
<body onload='timer=setInterval(countUP, 1000 );'>
<div id="timer_container">0</div>
<!-- append 'onclick' event to the button (or set the event in script section) -->
<a class="report-post-button" onclick="doStuff('Stuff done!');" id="report-post-submit">do stuff</a>
</body>
相关文章:
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何包含特定于每个视图angularjs的javascript文件
- Javascript日期格式类似于ISO,但本地
- 通过传递图像的URL通过javascript读取/处理图像-类似于PHP中的file_get_contents
- JavaScript:单击时相对于父级增加变量值
- JavaScript不适用于internet explorer和Firefox,但适用于谷歌
- 正则表达式(JavaScript),用于创建数字必须大于x的数据验证
- 依赖于缓慢加载javascript的UI
- 如何处理javascript中的循环引用,类似于Excel提供迭代限制的方式
- 适用于多种浏览器的Selenium-需要能够执行javascript的webDriver
- Javascript元素相对于屏幕的位置
- JavaScript对象作为哈希?复杂性是否大于O(1)
- XQuery 序列等效于 MarkLogic 服务器端 JavaScript
- 如何在JavaScript中创建类似于something.function()的函数
- JavaScript相当于Smalltalk开发周期
- Javascript平等三重等于,但是大于和小于呢?
- Javascript 认为 8 大于 12
- javascript中大于oper的属性在xslt中不起作用
- Javascript数字大于数字不能返回正确的结果
- 布尔逻辑——Javascript表达式:大于x和大于y的两倍