我想在文本框上的回车键上提交表单。
这是我的HTML代码:
<form class="locationform" id="locationform" method="get">
<fieldset class="col-md-12 center" id="Searchform">
<h4><b>Job Search</b></h4>
<div>
<label for="Locationtxt" style="padding-right:5px"><b>Location:</b></label>
<input id="Locationtxt" name="name" type="text" placeholder="Zip Code or City, State" runat="server" required>
<asp:Button CssClass="BtnSubmit" ID="BtnSubmit" runat="server" Text="Submit" OnClick="BtnSubmit_Click" />
</div>
</fieldset>
</form>
这是我在Jquery中尝试的代码:
$("#Locationtxt").keyup(function (event) {
if (event.keyCode == 13) {
$("#BtnSubmit").click();
}
});
这是页面加载后呈现的html
<form class="locationform" id="locationform" method="get">
<fieldset class="col-md-12 center" id="Searchform">
<h4><b>Store Job Search</b></h4>
<div>
<label for="Locationtxt" style="padding-right:5px"><b>Location:</b></label>
<input name="dnn$ctr2781$View$Locationtxt" type="text" id="dnn_ctr2781_View_Locationtxt" placeholder="Zip Code or City, State" required="" />
<input type="submit" name="dnn$ctr2781$View$BtnSubmit" value="Submit" id="dnn_ctr2781_View_BtnSubmit" class="BtnSubmit" style="color:White;background-color:Black;font-weight:bold;" />
</div>
</fieldset>
</form>
<div id="dnn_ctr2781_View_storedetails"></div>
<script>
function LoadMap(obj) {
var fsid = obj;
$('#Iframe_' + fsid).attr('src', $('#hdn_' + fsid).attr('value'));
}
$(document).ready(function () {
$("input").keyup(function (event) {
if (event.keyCode == 13) {
$("[id$='BtnSubmit']").click();
}
});
});
</script>
这对我没有用。有人可以建议我吗?
最佳答案
文档准备好后,您是否尝试添加代码?
$(document).ready(function() {
$("#Locationtxt").keyup(function (event) {
if (event.keyCode == 13) {
$("#BtnSubmit").click();
}
});
});
关于javascript - 在文本框中的Enter键上提交,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40025643/