我的页面有三个html选择标记。jQuery的更改()不起作用
我想这三个选择标签具有以下功能:
当我改变SELECTA,不是根据SELECTA selectB自动变化。 当selectB的选项已经创建,当我改变selectB比selectC自动改变selectB。
(
例如...
第一SELECTA的选项有歌星,影星,selectB只是空的。
当歌手选项选中,selectB自动创建选项 “Lady Gaga的”,“ Celine Dion“,”惠特尼休斯顿“,如果三位歌手创作过,当我选中”Lady Gaga“时,selectC将创建”生日“,”Facebook“,”google +“选项
当检查影片星标选项时, selectB自动创建选项“Bruce Wi llis“,”马特达蒙“,”威尔史密斯“,如果三个电影明星创建,当我选中”布鲁斯威利斯“时,selectC将创建”生日“,”Facebook“,”谷歌+“选项。
)
我的问题是...当我改变selectB,$( “#selectB_id”)变化()无法正常工作
以下是我的javascript代码:
$(function(){
$("#lineselect").change(function() {
$.ajax({
url: '/lineflow/ajaxgetselect',
type:'POST',
data:{ service_id:$("#lineselect option:checked").val() , level:1 },
success: function(res){
var obj = jQuery.parseJSON(res);
if($("#lineselect").val() == 0)
{
$("#second_li").html("");
$("#third_li").html("");
}
else if($("#lineselect").val() == 1)
{
$("#second_li").html("");
$("#third_li").html("");
$("#second_li").html('<select id="service_type" name="service_type"><option value="0">ALL</option></select>');
$("#third_li").html('<select id="service_name" name="service_name"><option value="0">ALL</option></select>');
for(i=0; i<obj.length; i++)
{
$('#service_type').append($("<option></option>")
.attr("value",obj[i].id)
.text(obj[i].name));
}
}
else if($("#lineselect").val() == 2)
{
$("#second_li").html("");
$("#third_li").html("");
$("#second_li").html('<input type="text" id="url_name" name="url_name"></input>');
}
else if($("#lineselect").val() == 3)
{
$("#second_li").html("");
$("#third_li").html("");
$("#second_li").html('<select id="url_type" name="url_type"><option value="0">ALL</option></select>');
for(i=0; i<obj.length; i++)
{
$('#url_type').append($("<option></option>")
.attr("value",obj[i].id)
.text(obj[i].name));
}
}
},
error: function(obj, status, err){}
});
});
$("#service_type").change(function() { // this change not work!!!
$.ajax({
url: '/lineflow/ajaxgetselect',
type:'POST',
data:{ service_id:$("#service_type option:checked").val() , level:2 },
success: function(res){
var obj = jQuery.parseJSON(res);
$("#third_li").html("");
$("#third_li").html('<select id="service_name" name="service_name"><option value="0">ALL</option></select>');
for(i=0; i<obj.length; i++)
{
$('#service_type').append($("<option></option>")
.attr("value",obj[i].id)
.text(obj[i].name));
}
},
error: function(obj, status, err){}
});
});
});
试试 “上” 而不是 “变化”:$(...)在( '变', ...) – Atber
@Aber没有区别......'.change(func)'只是'.on(“change”,func)的快捷方式' – Ian