2016-07-15 102 views
-7

我的HTML和CSS在這裏。我已經從流行網站w3schools.com獲得這些代碼。我必須寫什麼地方?爲什麼我的搜索框沒有搜索任何內容?

<html> 

<head> 
<style> 
input[type=text] { 
width: 130px; 
box-sizing: border-box; 
border: 2px solid #ccc; 
border-radius: 4px; 
font-size: 16px; 
background-color: white; 
background-image: url('searchicon.png'); 
background-position: 10px 10px; 
background-repeat: no-repeat; 
padding: 12px 20px 12px 40px; 
-webkit-transition: width 0.4s ease-in-out; 
transition: width 0.4s ease-in-out; 
} 

input[type=text]:focus { 
width: 100%; 
} 
</style> 
</head> 
<body> 

<p>Animated search form:</p> 

<form> 
<input type="text" name="search" placeholder="Search.."> 
</form> 

</body> 
</html> 

感謝

+0

您的'

'標記需要通過'method'和'action'屬性知道要搜索的內容。 – Lee

+0

[HTML5佔位符屬性不能代替標籤元素](http://www.456bereastreet.com/archive/201204/the_html5_placeholder_attribute_is_not_a_substitute_for_the_label_element/) – Quentin

+1

@Lee - 這是一個搜索表單,所以GET請求很好,所以由於GET是默認的,因此不需要方法屬性。 – Quentin

回答

3

guide you appear to have followed叫做「如何創建一個動畫搜索表單」,不幸的是它是一個指南,完全是對「動畫」頁面,並沒有任何與搜索。

表單的目的不是執行搜索。它是從用戶收集數據並將其發送到服務器端程序。

您需要編寫(或查找)將執行搜索的服務器端程序。

從您的服務器支持的服務器端代碼中挑選一種編程語言開始。

+0

您能否爲我編寫代碼 –

+0

@SumairAli - 不,這是一個非常廣泛的任務。 – Quentin

-1

這只是html設計頁面。你必須編寫一些搜索代碼。像onchange事件你的代碼做什麼。

創建一個javascript函數並在onchange事件中調用該函數。

+0

我正在使用博客可以請你爲我寫js代碼 –

0

正如你在評論中說的,你正在使用博客。在博客中使用此表單。它的工作原理

<form action='/search' class='search-form' method='get' role='search'> 
    <input class='form-control' name='q' placeholder='search' type='text'/> 
</form>