我试图单击“提交”按钮,并使用纯JavaScript提交表单。我试过了:
document.getElementById('sell_form').submit();
和
for(var i=0;i<document.getElementsByName('operation').length;i++){
if(document.getElementsByName('operation')[i].value=='Sell'){
document.getElementsByName('operation')[i].submit();
}
}
但我无法理解。谁能告诉我我该怎么做?
提前致谢。
Web代码是:
<form id="sell_form" class="ajaxform" action="/member/sell" method="post">
<div id="result" class="popup"> </div> //hidden
<div class="c-box-body">
<table width="100%" border="0">
<div style="text-align:center">
<br>
<input type="hidden" value="13" name="pair"> //hidden
<input type="hidden" value="Sell" name="type"> //hidden
<input type="submit" value="Calculate" name="calculate">
<input type="submit" value="Sell" name="operation"> //**This is the one I'm trying to click on
<input type="reset" value="Clear">
</div>
</div>
</form>
造成这种困难的原因是该网页不是我的(我在firefox中使用的是oilmonkey,这实际上是onload javascript事件)
最佳答案
<script type="text/javascript">
function callSubmit() {
document.forms[0].submit();
}
</script>
<form id="sell_form" class="ajaxform" action="/member/sell" method="post">
<div id="result" class="popup"> </div> //hidden`enter code here`
<div class="c-box-body">
<table width="100%" border="0">
<div style="text-align:center">
<br>
<input type="hidden" value="13" name="pair"> //hidden
<input type="hidden" value="Sell" name="type"> //hidden
<input type="submit" value="Calculate" name="calculate">
<input type="submit" value="Sell" name="operation" onclick="callSubmit()">
<input type="reset" value="Clear">
</div>
</div>
</form>