2011-10-22 322 views
1

我不想提交按鈕,因爲我希望人們能夠進入表單域,然後搜索他們所要做的就是按下回車按鈕。如何通過按下Enter鍵(不提交按鈕)來提交HTML表單?

這裏是我的代碼:

HTML

<div class="search"> 
<div class="search1" form action="weezyresults.php" method="post"> 
<input type="text" name="search" size="30" value="" 
style="background-color:white; border: 
solid 1px #ffffff; height: 30px; font-size:19px; 
font-family: HelveticaNeue-Light; font-weight: 1; 
vertical-align:9px;color:#151515" 
onfocus="if(this.value == ''){this.value = 
'';this.style.color='#363D42'}" /> 

</div> 
<div class="enter"><input type="image" src="but.jpg" alt="Submit"></div> 

CSS

.search { 
background: #FFFFFF; 
border: 1px solid; 
color: #BDBDBD; 
height: 35px; 
width: 270px; 
} 


.search1 { 
margin-top: 3px; 
float: left; 
} 

.enter { 
display:none; 
} 

謝謝!

詹姆斯

+0

請編輯HTML代碼的第一部分爲更好的可讀性。你在開始時使用更多的空白來做到這一點。謝謝。 – Smamatti

+0

這裏的一個很好的做法是接受最好的答案作爲讚賞的標誌並幫助其他用戶能夠更快找到最佳答案 – Anonymous

回答

4
<div class="search1" form action="weezyresults.php" method="post"> 

應該

<div class="search1"> 
<form action="weezyresults.php" method="post"> 
1

包括提交按鈕,但風格它:

display:none; 

你也有你的語法錯誤:

<div class="search1" form action="weezyresults.php" method="post"> 

需求是

<div class="search1"> <form action="weezyresults.php" method="post"> 

祝你好運!

+0

嗨,感謝您的回覆!請檢查我上面更新的問題,我做了我認爲可行的事情,但事實並非如此! – James

+0

編輯我的答案。這個錯誤會導致它不工作! – Anonymous

0

寫js函數並說哪個將發佈表單。僞代碼將是

funciton post() 
{ 
    if(keycode==13) 
    __dopostback(); 
} 

如果你使用jQuery的話,你可以使用

jquery("form selector").post() 
+0

複雜 –

-2

那麼你應該做的是這樣的。

function formSubmit(element, ev) { 
//element is the this selector for current element and ev is the event-trigger to get keycode 
if (ev.keyCode === 13) { // 13 is the keycode for Enter-button 
    element.form.submit(); //Then submit the button 
} 
} 

並將此onkeypress="submiter(this,event)"添加到您的輸入字段。

+2

這就是要點。他不想! - 這是沒有用的,你不應該這樣做,但他想要的東西像:'onkeypressed =「checkForReturn()」'然後執行'this.form.submit();'。 – Smamatti

+0

我不想提交按鈕我只想要文本字段,並且一旦他們輸入了文本int他的文本字段,他們所要做的就是按回車。這是如何實現的? – James

+0

太硬編碼和非標準。任何人閱讀代碼將會是吧? –