簡體   English   中英

按下ENTER鍵時,表單未發布到服務器

[英]Form not posting to server when ENTER key is pressed

我有一個簡單的DIV,顯示用戶名:

<div id="firstNameChange" title="Click to edit" style="vertical-align:top; display:inline-block; float:left;"><?=$firstName?></div>

當用戶用鼠標單擊div時,它將變成一種形式:

<form method="post" action="" >
  <div id="firstNameChange" title="Click to edit" style="vertical-align:top; display:inline-block; float:left;"><?=$firstName?></div>
  <input type="hidden" name="firstName" id="firstName" value="<?=$firstName?>"/>
  <input type="submit" name="submitFirstName" id="saveFirstName" class="ui-icon ui-icon-disk" style="border:none; display:none; background-color:transparent; float:right; vertical-align:top;" />
</form>

使用jQuery:

$("#firstNameChange").click(function() { 
    //check if there are any existing input elements
    if ($(this).children('input').length == 0) {
        $("#saveFirstName").css("display", "inline");
        //variable that contains input HTML to replace
        var inputbox = "<input type='text' class='inputbox' name='firstName' value=\""+$(this).text()+"\">";    
        //insert the HTML intp the div
        $(this).html(inputbox);
        //automatically give focus to the input box     
        $(".inputbox").focus();
        //maintain the input when it changes back to a div
        $(".inputbox").blur(function() {
            var value = $(this).val();
            $("#firstName").val(value);
            $("#firstNameChange").text(value);
        });
    }               
});

問題是,僅當用鼠標單擊“提交”按鈕時,表單才回發到服務器。 如果用戶要敲擊鍵盤上的Enter鍵,則不會回發。 有什么建議么?

找到了答案。 我刪除了隱藏的元素,並且一切正常。 感謝大家的支持!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM