2015-03-13 23 views
0

我有一個主文本框(月),其中的變化,下拉菜單是爲另一個文本框(天)創建的。一旦我有這些人口,我保存它。現在,當我回去編輯它時,我直接想要更改Days文本框中的選項,但由於在更改文本框「Months」時觸發了Days的下拉菜單,所以我沒有獲得天的下拉菜單。 以下是我的代碼:如何在沒有任何更改事件的情況下讓jquery中的下拉列表適用於後續時間?

function editValues() { 
    //initializations 
    $('.Months').on("change", function(){ 
    monthsValueSet = this.value; 

    //pass monthsValueSet to database to retrieve values 
    $('.Days').html(""); 

    for(i=0;i<data.length;i++){ 
    $('.Days').append('<option>' + data[i].days + '</option'); 
    } 

    }); 
    } 
//code for Save button 
//code for edit 
$("#daysMonthsTable").on("click", ".edit-months", function(event){ 
editValues(); 
});  

我的HTML代碼:

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
<tr> 
<td> 
    <div class="Months"> 
    <table> 
    <tbody> 
    <tr> 
    <td><label>Months</label></td> 
    <td ><input type="text" class="Months"></td> 
    </tr> 
    </tbody> 
    </table>       
</div> 
</td> 

<td> 
<div class = "Days"> 
<table> 
<tbody> 
<tr> 
    <td><label>Days</label></td> 
<td><input type="text" class="Days"></td> 
    </tr>           
</tbody> 
    </table>       
</div> 
</td> 
</tr> 
</body> 
</html> 
+0

我不太清楚,如果我理解你的問題,但如果我有它正確的,那麼你需要確保你所有的觸發器鎖定在你不更新的元素... – holroy 2015-03-13 17:53:50

回答

0

執行以下

$("#daysMonthsTable").on("click", ".edit-months", function(event){ 
    editValues(); 
    $('.Months').trigger("change"); 
}); 
+0

我試過'.trigger',但它沒有幫助。當我手動去更改月份字段時,它顯然會得到更改事件,併爲我提供天數的下拉菜單 – pal 2015-03-13 15:37:07

相關問題