[英]click on button1 and add text to div, click on button2 and remove text and css style button1
[英]Javascript click button1
我有以下HTML代码,我正在尝试制作一个JavaScript以单击此按钮
<fieldset class="fields1"></fieldset>
<fieldset class="submit-buttons">
<some other button here >
<input class="button1" type="submit" value="Submit" name="post" tabindex="4" accesskey="f"></input>
我尝试了以下两行代码,但都不行:
$(".submit-buttons").children('input[name="post"]').click();
$("input[name=post]").click();
还有其他方法可以单击按钮1吗? 有没有一种方法可以通过其tabindex或accesskey选择按钮?
单击功能用于事件处理而不触发事件。 如果要触发点击使用触发器
$("input[name=post]").trigger('click');
您忘记了关闭<fieldset>
标记
使用以下标记
<fieldset class="fields1"></fieldset>
<fieldset class="submit-buttons">
<input class="button1" type="submit" value="Submit" name="post" tabindex="4" accesskey="f">
</fieldset>
另外,您需要在click function
内添加event handler
回调
$(".submit-buttons").children('input[name="post"]').click(function(){
alert("clicked")
});
并手动或通过jQuery的trigger()
触发click事件
$("input[name=post]").trigger('click')
这是演示
首先链接任何jQuery版本,然后喜欢
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
$("input[name=post]").click(function(){
alert('dddd');
});
如果准备就绪,请点击
$("input[name=post]").trigger('click');
<form action="#" method="post">
<input class="button1" type="submit" value="Submit" name="post" tabindex="4" accesskey="f"></input>
</form>
start <form> end </form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.