我有一个html字符串,我需要放入一个输入选择,但它超出了输入选择的位置......我想,看看我正在构建的选项变量?在任何一个类.product之后它需要在下一个选择内部...请告知。
$(".product").change(function(){
//get selected option of the select that changed
var selected = $(this).val();
//then create the url to reference the value of the selected option (product id)
var url = "/order/getpricing/" + selected;
//remove all options from that nearby select statement
$(this).next('select').children().remove();
var pricelist = $(this).next('select');
$.getJSON(url, function(data, pricelist){
var options = '';
for(n = 0; n < data.length; n++){
options += '<option value="' + data[n].volumeID + '">' + explainPricing(data, n) + '</option>';
//setMeGlobal(options, "options");
}
$("#"+pricelist).html(options);
//TODO NEXT: SOMEHOW ADD OPTIONS TO THE SELECT!
});
$(this).next('select').html = options;
});
答案 0 :(得分:2)
尝试尽可能多地重复使用pricelist
变量。它可以自动提供给你的ajax处理程序,而不必传递它:
$(".product").change(function(){
//get selected option of the select that changed
var selected = $(this).val();
//then create the url to reference the value of the selected option (product id)
var url = "/order/getpricing/" + selected;
var pricelist = $(this).next('select');
//remove all options from that nearby select statement
pricelist.find('option').remove();
$.getJSON(url, function(data) {
var options = '';
for(n = 0; n < data.length; n++){
options += '<option value="' + data[n].volumeID + '">' + explainPricing(data, n) + '</option>';
//setMeGlobal(options, "options");
}
pricelist.html(options);
});
});