2014-01-29 29 views
-1

空白我有一個表格設置像這樣:的jQuery提交搜索查詢並顯示輸入的文字

<form id="search"> 
    <input id="searchbox" type="text" size="40" placeholder="your search.." /> 
</form> 

的Javascript:

$('#searchbox').keypress(function (e) 
{ 
    e.preventDefault(); 
    if (e.which == 13) 
    { 
     hitParse(); 
    } 
}); 

function hitParse(){ 

    // here parse api posts query to parse.com servers 
} 

現在,如果我鍵入#searchbox就不會顯示鍵入的文本因爲e.preventDefault()我猜,但是當我按下輸入它執行hitParse()罰n發送空白查詢所有。但是,如果我刪除preventDefault()然後它顯示鍵入的文本罰款,但hitParse()不執行。我如何能夠同時實現:顯示輸入的文本,並訪問文本,並按下時與實際鍵入的查詢

回答

2

移動preventDefault進入hitParse()進入if語句

$('#searchbox').keypress(function (e) 
{ 

    if (e.which == 13) 
    { 
     e.preventDefault(); 
     hitParse(); 
    } 
}); 

function hitParse(){ 

    // here parse api posts query to parse.com servers 
} 
+0

的感謝!我超級笨! – timmaktu