我有一个没有输入类型提交的表单。
<form class="form" action="" method="post" name="new-service"
enctype=multipart/form-data>
<span class="pull-right">
<input id="sa" name="Searchs" type="text" placeholder="Analyze Search"
class="form-control input-xlarge search-query center-display"
required="">
<span class="pull-right"> <a class="btn btn-success" href="#"
onclick="
this.href='/recrawl?search=' + document.getElementById('sa').value;
somefunction(this, event);
return true;
"> Analyze Data </a>
<br><br>
</span>
</form>
当点击分析数据时,上面的表单就会工作。
但现在我希望它在按输入类型文本标记的 Enter 时运行
我试过了
<input id="sa" name="Searchs" type="text" placeholder="Analyze Search"
class="form-control input-xlarge search-query center-display" required=""
onclick="
this.href = '/recrawl?search=' + document.getElementById('sa').value;
somefunction(this, event);
return true;
">
但它不起作用?
最佳答案
<input id="sa" name="Searchs" type="text" placeholder="Analyze Search" class="form-control input-xlarge search-query center-display" required="" onKeyPress="postURL(event, this)">
function postURL(e, textarea){
var code = (e.keyCode ? e.keyCode : e.which);
if(code == 13) { //Enter keycode
window.location.href ='/recrawlsearch='+document.getElementById('sa').value;
}
}
希望这个 window.location.href 能够帮助您。
关于javascript - 如何在html中输入文本作为提交按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31801787/