1
:我有JS製作回車鍵(鍵盤)提交我的形式看起來像這樣的信息--Jquery
<body>
<form id="myForm" method="post">
<label>id:</label>
<input type="text" name="id" id="id" size="50"/>
<div id="hidden" style="display: none;">
<label>Name:</label>
<input type="text" name="name" size="50"/><br/>
<input type="button" id="button2" value="Update" size="25" /> <br/>
</div>
<input type="button" id="button1" value ="Get Info" onclick="document.getElementById('hidden').style.display = ''; this.style.display = 'none'" size="25"/>
,看起來像這樣
$(document).ready(function(){
$("#button1").click(function(){
$.post(
'xxx.php',
{ id: $('input[name="id"]', '#myForm').val() },
function(json) {
if (json.abc === 'no'){
alert('does not exist');
}
else{
$("input[name='name']").val(json.name);
}},
"json"
);
});
$("#button2").click(function(){
$('form#myForm').attr({action: "xxx1.php"});
$('form#myForm').submit();
});
});
的問題是,用戶只能通過點擊提交按鈕來提交此表單。關於如何調整js以使輸入按鈕(在鍵盤上)也提交表單的任何想法?
注意:有兩個提交按鈕都相互關聯。
如果用戶點擊輸入確實,哪個提交被觸發?這可能有所幫助:http://stackoverflow.com/questions/302122/jquery-event-keypress-which-key-was-pressed – dmcnelis
刷新......... –
所以當你說相通,你的意思是他們兩者都觸發相同的動作呢? – dmcnelis