Javascript jQuery是否总是附加选定项两次?

Javascript jQuery是否总是附加选定项两次?,javascript,jquery,Javascript,Jquery,我用jQuery附加了新表单,当我从下拉列表中选择一个项目时,我需要在它下面添加div/form,但它总是附加两次。我不知道为什么!另一个jquery元素没有添加它,我已经检查过了,我正在jquery的函数内部使用它 这是我的密码 function addBrand( brandName ) { jQuery('#example').append('' + '<form name="search" action="" met

我用jQuery附加了新表单,当我从下拉列表中选择一个项目时,我需要在它下面添加div/form,但它总是附加两次。我不知道为什么!另一个jquery元素没有添加它,我已经检查过了,我正在jquery的函数内部使用它

这是我的密码

function addBrand( brandName )
    {

            jQuery('#example').append('' +
                '<form name="search" action="" method="get" id="search">' +
                '<div class="add_marke parentElement" id="add_marke_'+brandName+'"  > ' +
                '   <div class="car_tag"><span  class="lbl">' +brandName+ '&nbsp' + '&nbsp;<span id="car_name" class="icon-remove car-remove"></span></span></div> ' + '&nbsp' +
                '   <input type="hidden" name="markeName" id="markeName" value="'+brandName+'"></input>'+
                '   <select  name="model_cars" id="model_cars_'+brandName+'" class="search_dropdown_small ">' +
                '       <option id="selectModel" name="selectModel_All" value="all" >Alle </option>' +
                '       <option id="selectModel_Selected" name="selectModel_Selected" value="selected" >Nur gewählte</option>'+
                '       <option id="selectModel_Excluded" name="selectModel_Excluded" value="exclude" >Alle au&#xdf;er</option>' +
                '   </select>'+ '&nbsp' +

                '</div>' +
                '</form>');

 return(this);

    }

    jQuery("#model").change(function(){
        var brandName = jQuery("#model").val();
        jQuery(this).ready(addBrand(brandName));
    });
功能添加品牌(品牌名称)
{
jQuery('#示例').append(''+
'' +
' ' +
''+brandName+'+''+'''+'+
'   '+
'   ' +
“Alle”+
“Nur gewählte”+
“Alle auß;er”+
''+''+
'' +
'');
返回(本);
}
jQuery(“#model”).change(函数(){
var brandName=jQuery(“#model”).val();
jQuery(this.ready)(addBrand(brandName));
});
应该这样读:

function addBrand( brandName )
  {

    jQuery('#example').append('' +
      '<form name="search" action="" method="get" id="search">' +
      '<div class="add_marke parentElement" id="add_marke_'+brandName+'"  > ' +
      '   <div class="car_tag"><span  class="lbl">' +brandName+ '&nbsp' + '&nbsp;<span id="car_name" class="icon-remove car-remove"></span></span></div> ' + '&nbsp' +
      '   <input type="hidden" name="markeName" id="markeName" value="'+brandName+'"></input>'+
      '   <select  name="model_cars" id="model_cars_'+brandName+'" class="search_dropdown_small ">' +
      '       <option id="selectModel" name="selectModel_All" value="all" >Alle </option>' +
      '       <option id="selectModel_Selected" name="selectModel_Selected" value="selected" >Nur gewählte</option>'+
      '       <option id="selectModel_Excluded" name="selectModel_Excluded" value="exclude" >Alle au&#xdf;er</option>' +
      '   </select>'+ '&nbsp' +

      '</div>' +
      '</form>');

    return true;

  }

  jQuery(document).ready(function(){
    jQuery("#model").change(function(){
      var brandName = jQuery("#model").val();
      addBrand(brandName);
    });
  });
功能添加品牌(品牌名称)
{
jQuery('#示例').append(''+
'' +
' ' +
''+brandName+'+''+'''+'+
'   '+
'   ' +
“Alle”+
“Nur gewählte”+
“Alle auß;er”+
''+''+
'' +
'');
返回true;
}
jQuery(文档).ready(函数(){
jQuery(“#model”).change(函数(){
var brandName=jQuery(“#model”).val();
addBrand(brandName);
});
});
试试这个

function addBrand( brandName )
    {

            $('#example').append(
                '<form name="search" action="" method="get" id="search">' +
                '<div class="add_marke parentElement" id="add_marke_'+brandName+'"  > ' +
                '   <div class="car_tag"><span  class="lbl">' +brandName+ '&nbsp' + '&nbsp;<span id="car_name" class="icon-remove car-remove"></span></span></div> ' + '&nbsp' +
                '   <input type="hidden" name="markeName" id="markeName" value="'+brandName+'"></input>'+
                '   <select  name="model_cars" id="model_cars_'+brandName+'" class="search_dropdown_small ">' +
                '       <option id="selectModel" name="selectModel_All" value="all" >Alle </option>' +
                '       <option id="selectModel_Selected" name="selectModel_Selected" value="selected" >Nur gewählte</option>'+
                '       <option id="selectModel_Excluded" name="selectModel_Excluded" value="exclude" >Alle au&#xdf;er</option>' +
                '   </select>'+ '&nbsp' +

                '</div>' +
                '</form>');


    }
 $("#model").change(function(){
    var brandName = $("#model").val();
     addBrand(brandName);
});
功能添加品牌(品牌名称)
{
$('#示例')。追加(
'' +
' ' +
''+brandName+'+''+'''+'+
'   '+
'   ' +
“Alle”+
“Nur gewählte”+
“Alle auß;er”+
''+''+
'' +
'');
}
$(“#模型”).change(函数(){
var brandName=$(“#model”).val();
addBrand(brandName);
});
如果不想追加,请使用
.html(
代替
.append(

选中


另一个

只有当前文档有一个
就绪的
处理程序,元素不删除
返回(此);
或者简单地使用
返回true
我做了一个更改,但它总是显示double,我选择的每一项都会显示double。可能有一种情况是,您为同一事件附加了两个处理程序,并且在您更改模型文本时,这两个处理程序都会被触发!请创建并共享一把相同的小提琴!我做了一个更改,但它总是会被触发s显示加倍,我选择的每一项都加倍。我不知道会有什么错误。你能创造并分享一把相同的小提琴吗?太好了!