2015-11-07 66 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");