计时器从40变为0,脚本应该等到只有100毫秒并按下按钮。
如何获得该数字,因此它将是x = 14.22 * 1000-100?
我知道我需要删除te字母,但是如何删除?
只是javacript,没有jquery!
var evt = document.createEvent("MouseEvents");
var run = document.getElementByClassName("button1");
setInterval(function() {
var time = document.getElementByClassName("Timer h4").innerHTML;
var x = time * 1000 - 100;
setTimeout(function() {
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
run.dispatchEvent(evt);
}, x);
}, 15000);
function x3a() {
document.getElementById("x3").innerHTML = 1;
}
<h4 class="Timer h4">Time expire in 14.22</h4> //how can I read this number 14.22 so I can use it?
<p id="x3"></p>
<button data-g="red" class="button1" onclick="x3a()">OK</button>
答案 0 :(得分:2)
选取h4
元素,并使用正则表达式匹配数字。
const el = document.querySelector('h4');
const txt = el.innerText.match(/\d+\.\d+/)[0];
console.log(txt);
<h4 class="Timer h4">Time expire in 14.22</h4>