嗨朋友们需要你的帮助,我有一个从一个html页面导航到另一个页面的场景
从html第1页导航到html page2,其中包含三个具有不同ID的按钮。我必须在页面加载时选择第一个按钮,并且必须获取其所有参数值onclick事件。
<html>
<body>
<a href="htmlpage2.html">click here</a>
</body>
</html>
<html>
<body>
<button id="button1" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<button id="button2" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<button id="button3" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<script type="text/javascript">
function save(name,shape,made){
alert(name);
alert(shape);
alert(made);
}
</script>
</body>
</html>
## scenario ##
On navigating to html page2 i have to make the button with id="button1" to be clicked default and have to get alert(); as if give in the save function hope will get a better response thank You
答案 0 :(得分:1)
<script type="text/javascript">
function save(name,shape,made){
alert(name);
alert(shape);
alert(made);
}
$("#button1").trigger("click")
</script>
答案 1 :(得分:1)
您可以使用此代码。
<html>
<body>
<button id="button1" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<button id="button2" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<button id="button3" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<script type="text/javascript">
function save(name,shape,made){
alert(name);
alert(shape);
alert(made);
}
document.getElementById("button1").click();
</script>
</body>
</html>
答案 2 :(得分:0)
你可以试试这个:
document.getElementById('button1').click();
答案 3 :(得分:0)
<button id="button1" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<button id="button2" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<button id="button3" class="btn btn-default" onclick="save('Ice','cube','water')">click
</button>
<script type="text/javascript">
function save(name, shape, made) {
alert(name);
alert(shape);
alert(made);
}
document.getElementById("button1").click();
</script>
答案 4 :(得分:0)
如果不使用jquery,
document.getElementById('button1').click();