简体   繁体   中英

autoClick at the same time error

i create two button in index.html. The two buttons will function differently. I'm trying to give the autoclick function to both, but I get an error.

<html>

<head>
<script>
function autoClick(){
document.getElementById('linkToClick').click(); }
</script>

<script>
function autoClick(){
document.getElementById('linkToClick2').click();}
</script>
<head>

<body onload="setInterval('autoClick();',5000);">   
<button  type="" id="showNotifications" >
<a id="linkToClick" target="_blank" >Bildirim yolla</a>
</button>
</body>

<body onload="setInterval('autoClick();',1000);">   
<button  type="" id="showNotifications3" >
<a id="linkToClick2" target="_blank" >Bildirim</a>
</button>
</body>

</html>

The two buttons are sending notifications. Haven't problem. But they are auto clicking at the same time. Why "showNotifications3" button doing an autoclick in 5 seconds, not in 1 second?

You cannot have two js methods with same name. You can use something given below, Also I have removed two body tags.

<html>
<head>
<script>
function autoClick1(){
    // alert("1")
    document.getElementById('linkToClick').click(); 
}

function autoClick2(){
    // alert("2")
    document.getElementById('linkToClick2').click();
}
function callOnLoad(){
    setInterval('autoClick1();',5000);
    setInterval('autoClick2();',1000);
}
</script>
<head>

<body onload="Javascript: callOnLoad();">   
<button  type="" id="showNotifications" >
<a id="linkToClick" target="_blank" >Bildirim yolla</a>
</button>
<button  type="" id="showNotifications3" >
<a id="linkToClick2" target="_blank" >Bildirim</a>
</button>
</body>

</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM