![](/img/trans.png)
[英]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.