<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>