2012-04-30 66 views
0

與jQuery我想讓多個文本字段出現.. 當單擊該文本Jquery的,每次點擊按鈕,一個文本框出現

<form> 
<input style="margin-top:20px;margin-right :50px; width:255px;height:23px;float:left;" type="text" name="CrawlerField"id="CrawlerField"/> 
<input style="margin-top: 15px; margin-right :50px; width:255px;height:23px;float:left;" type="text" name="CrawlerField1" id="CrawlerField1"/> 
<input style="margin-top: 15px; margin-right :50px; width:255px;height:23px;float:left;" type="text" name="CrawlerField1" id="CrawlerField2"/> 
<font id="jqueryAdd">Add button</font> 
</form> 

這是文本時,單擊時出現一個新的文本字段... 。

在啓動所有的文本框都隱藏
<font id="jqueryAdd">Add button</font> 

腳本

$("#CrawlerField1").hide(); 
$("#CrawlerField2").hide(); 

當點擊該單詞,添加與jqueryAdd 檢查定義按鈕,如果以前的文本字段是隱藏的文本框旁邊出現在啓動

$("#jqueryAdd").click(function (event) { 
     if($("#CrawlerField").is(":visible")) 
     $("#CrawlerField1").show(); 
     return false; 
}); 
$("#jqueryAdd").click(function (event) { 
     if($("#CrawlerField1").is(":visible")) 
     $("#CrawlerField2").show(); 
    return false; 
}); 

該代碼產生的所有按鈕的外觀!

回答

0

添加class到所有<input>標籤,如

<input class ="in" style="margin-top:20px;margin-right :50px; width:255px;height:23px;float:left;" type="text" name="CrawlerField"id="CrawlerField"/> 
<input class ="in" style="margin-top: 15px; margin-right :50px; width:255px;height:23px;float:left;" type="text" name="CrawlerField1" id="CrawlerField1"/> 
<input class ="in" style="margin-top: 15px; margin-right :50px; width:255px;height:23px;float:left;" type="text" name="CrawlerField1" id="CrawlerField2"/> 

和jQuery中加入這一行開始隱藏所有的輸入。

$(".in").hide(); 
相關問題