I'm just wondering how I can use JavaScript to simulate a click on an element.
(我只是想知道如何使用JavaScript模拟元素的点击。)
Currently I have:
(目前我有:)
<script type="text/javascript">
function simulateClick(control)
{
if (document.all)
{
control.click();
}
else
{
var evObj = document.createEvent('MouseEvents');
evObj.initMouseEvent('click', true, true, window, 1, 12, 345, 7, 220, false, false, true, false, 0, null );
control.dispatchEvent(evObj);
}
}
</script>
<a href="http://www.google.com" id="mytest1">test 1</a><br>
<script type="text/javascript">
simulateClick(document.getElementById('mytest1'));
</script>
But it's not working :(
(但这不起作用:()
Any ideas?
(有任何想法吗?)
ask by Belgin Fish translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…