2014-10-10 66 views
0

我需要jQuery的東西,這讓實現以下functionlity添加functionlity與驗證:如何實現克隆使用jQuery

1)上的「按鈕」的點擊,它應該允許增加新的(克隆)行元素(如如下面的HTML所示)。

2)在行元素中,它包含SELECT LIST,其綁定了CHANGE事件,如同一個下拉列表的選擇更改,填充另一個下拉列表。

3)此外,還有對點擊提交按鈕觸發的文本框進行驗證。所以,這也是基於文本框ID選擇器。

我無法實現上述功能,專門針對點#2和#3。

請指導我。

 <a href="#" class="show_hide1" style="text-decoration: none; color: inherit; float: right;"> 
     &nbsp;</a> 
    <h1 class="infoTitle clearfix"> 
    Other Class Information</h1> 
    <br /> 
<div id="hsOther" class="piTable slidingDiv1"> 
<div class="content1"> 
    <table class="divclass" width="100%"> 
     <tr class="tdStyle"> 
      <td> 
       <label class="customFont" for="OtherInstitueName"> 
        Class Name</label> 
      </td> 
      <td> 
       <label class="customFont" for="OtherAddress"> 
        Street Address</label> 
      </td> 
      <td> 
       <label class="customFont" for="OtherCity"> 
        City</label> 
      </td> 
     </tr> 
     <tr class="tdStyle"> 
      <td class="tdStyle"> 
       <select data-val="true" data-val-number="The field OtherStateId must be a number." 
        data-val-required="The OtherStateId field is required." id="Select1" name="OtherStateId" 
        style="font-family: Calibri; font-size: 16px;"> 
        <option value=""></option> 
        <option value="NI">NI</option> 
        <option value="UT">UT</option> 
        <option value="IO">IO</option>      
       </select> 
       <select data-val="true" data-val-number="The field OtherStateId must be a number." 
        data-val-required="The OtherStateId field is required." id="selectClass" name="OtherStateId" 
        style="font-family: Calibri; font-size: 16px;"> 
        <option value=""></option> 
        <option value="NI">NI</option> 
        <option value="UT">UT</option> 
        <option value="IO">IO</option>      
       </select> 
      </td> 
      <td class="tdStyle"> 
       <input id="OtherAddress" maxlenght="200" name="OtherAddress" style="font-family: Calibri; 
        font-size: 16px;" type="text" value="" /> 
      </td> 
      <td class="tdStyle"> 
       <input id="OtherCity" maxlenght="50" name="OtherCity" style="font-family: Calibri; 
        font-size: 16px;" type="text" value="" /> 
      </td> 
     </tr>   
     </table> 
    </div> 
</div> 

回答

0

對於任何新創建Elements,你必須重視的事件處理程序,因爲默認情況下它不會是具有任意。

如果你使用克隆方法從jquery進行克隆,那麼確保你克隆了事件(默認情況下克隆方法不克隆事件)。

也請分享您迄今嘗試過的代碼。一個jsfiddle將是有益的