因此,我不假設在此輸入字段上使用表單標記(導致每個後端人員的bug)如何將按鈕連接到無窗體輸入?我希望用戶能夠使用輸入密鑰
我將如何能夠允許用戶使用當輸入被選擇/激活以激活提交時,回車鍵?
用戶可以手動點擊Add Group提交按鈕,也可以點擊標籤,但他們不能隨便進入點擊:(
形式
<input type="text"
id="group-code" value="Type your Group Code Here" name="Type your Group Code Here"
onblur="if (this.value == '') {this.value = 'Type your Group Code Here';}"
onfocus="if (this.value == 'Type your Group Code Here') {this.value = '';}"
autocomplete="off"/>
<button class="btn" id="btn_join_group">add group</button>
<!--<input type="submit" id="btn_join_group" form="group-code" value="add group"/>-->
jQuery
$('#btn_join_group').unbind('click').bind("click", function(event) {
var newGroup = $('#group-code').val();
// Send Group code to server
WHOAT.networking.getToServerWithAjax('/groups/join', newGroup, function (response) {
var res = JSON.parse(response);
if (res.result === 'success') {
notification.setStatusAndFadeStatus(response);
} else if (res.result === 'error') {
notification.setStatusAndFadeStatus(response);
}
});
});
謝謝!這確實有用,而且我最終還是使表單工作,只需要返回false –
我很高興我可以幫助@LeonGaban! –