2015-11-07 63 views
1

我是JavaScript新用戶。點擊輸入javascript

我正在嘗試運行單擊網頁上的按鈕的Javascript代碼。 HTML代碼看起來像這樣:

<div class="felement fgroup" id="yui_3_17_2_2_1446895504264_827"><input name="savegrade" value="Save changes" type="submit" id="id_savegrade"> <input name="saveandshownext" value="Save and show next" type="submit" id="id_saveandshownext"> <input name="cancelbutton" value="Cancel" type="submit" onclick="skipClientValidation = true; return true;" class=" btn-cancel" id="id_cancelbutton"></div> 

該元素被稱爲'x'。我想點擊'id_saveandshownext'ID提交按鈕。

我曾嘗試:

x.getElementsById('id_saveandshownext').click(); 

沒有工作...... 我怎麼點擊這個按鈕?

+1

'getElementById()',而不是'getElement' ** s **'ById()'投票結束爲Typo – Kaiido

回答

0

您需要使用的文件是這樣的:

document.getElementById("id_saveandshownext").click(); 
0

因爲你使用jQuery,您可以使用以下 -

<script> 
//your function that exectues button to be clicked 
$(function(){ 
    $('#id_saveandshownext').click(); 
}); 
</script> 
-1

您也可以觸發這樣的單擊事件:

document.getElementById("id_saveandshownext").trigger("click");