fireevent dispatchevent 模擬支付寶輸入密碼

<button id="button" onclick="alert('btn點擊');">btn點擊</button>
<input id="button2" type="submit" href="javascript:alert('password')" >password</input>

<div id='hello'> hello</div>
<script>

    
    
    var t = document.getElementById('button')
    clickObj(t);
    
   t.addEventListener('click', function (event) {
        alert('正在吃飯...');
    })

    

    function clickObj(t) {
            if (document.all) {
                t.fireEvent("onclick");
            }
            else {
                var evt = document.createEvent('HTMLEvents');
                evt.initEvent('click', true, true);
                t.dispatchEvent(evt);
            }
    }
    
</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章