<div id="inputs">
<input type="text" value="">
<input type="text" value="">
</div>
<input type="button" id="add" value="Add input">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
$('#add').click(function(){
$('#inputs').append('<input type="text" value="">');
});
});
</script>
在上面的代碼中,我想添加一個搜索圖標用於與按鈕產生的每個新的輸入(ID =添加;在此未示出爲簡單起見)。這將是一個典型的輸入:添加搜索圖標,輸入框
<label>
<input type="text" class="search" name="word" autofocus="autofocus" />
<span class="search-icon">
<span class="glass"></span>
<span class="handle"></span>
</span>
</label>
使用CSS,我可以以固定的方式定位搜索圖標。
感謝
AMAZING解釋,毫無疑問它會工作,但是,你知道,如果我可以,比方說,讓搜索框透明,或更改的顏色搜索圖標? – j1nma
好吧,我提供的代碼在搜索框中搜索到搜索圖標,因此使搜索框變爲透明圖標。當然,您可以使用相對定位,這樣可以使搜索圖標和搜索框獨立。你可以編輯搜索圖標來改變顏色(這不能在CSS中完成),或者修改照片編輯程序的不透明度,或者從頭開始改變顏色,但我有點像我的搜索圖標。 :)這裏是相對定位的例子:http://jsfiddle.net/525h6/。您也可以通過追蹤來完成此操作,但這將會很有幫助 – 2012-12-24 16:56:51
關於我的答案中的代碼「outline:0」,我當時毫無頭緒,我認爲您最好閱讀http://outlinenone.com/。 – 2012-12-28 02:06:48