[英]How to Input type text as submit button in html?
我有一个没有输入类型Submit的表单。
<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>
单击Analyze Data即可完成以上表格的工作。
但现在我希望它按输入类型文本标签的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对您有所帮助。
input
元素没有href
属性,因此this.href = xxxx
无法正常工作。
如果要单击输入元素,请使用window.location.href = xxx
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.