Jquery jqtranform未应用于动态添加的字段

Jquery jqtranform未应用于动态添加的字段,jquery,jqtransform,Jquery,Jqtransform,我正在对表单字段使用jqtransform。当我将动态字段添加到表单中时,jqtransform不会应用于新字段。 请看样本代码 $(function(){ $('form#js_greatdeals_form').jqTransform(); $('#js_greatdeals_form div.jqTransformSelectWrapper ul li a').click(function(){ var value = $(this).parent().index();

我正在对表单字段使用jqtransform。当我将动态字段添加到表单中时,jqtransform不会应用于新字段。 请看样本代码

$(function(){

$('form#js_greatdeals_form').jqTransform();


$('#js_greatdeals_form div.jqTransformSelectWrapper ul li a').click(function(){
var value = $(this).parent().index();
      $("#select_cntry").attr('selectedIndex', value);
      var countryiso = $("#select_cntry").val();

        if(countryiso == 1) {
        var content = '<select name="state" id="state"><option value="s1">State1</option><option value="s2">State2</option></select>';
        $('#newselect').html(content);
        $('select#state').jqTransform(); //Newly added
        }
    }); 
});
$(函数(){
$('form#js_greatdeals_form').jqTransform();
$(“#js_greatdeals_form div.jqtransferormselectwrapper li a”)。单击(函数(){
var值=$(this.parent().index();
$(“#select_cntry”).attr('selectedIndex',value);
var countryiso=$(“#选择#cntry”).val();
如果(countryiso==1){
var内容='State1State2';
$('#newselect').html(内容);
$('select#state').jqTransform();//新添加
}
}); 
});
我的表格是

<form id="js_greatdeals_form" name="js_greatdeals_form" method="post">
  <select id="select_cntry">
    <option selected="selected">select</option>
    <option value="1">Country1</option>
    <option value="2">Country2</option>
  </select>
  <div id="newselect"></div>
</form>

选择
国家1
国家2
我尝试了[请参见注释行“新增”]给出的答案。但这种解决方案对我也不起作用。
请做必要的事。谢谢

打开jquery.jqtransform.js文件,找到以下行:

/* Fire the onchange event */
if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) {
    $select[0].selectedIndex = $(this).attr('index');
    $select[0].onchange();
 }
现在只需在该行下方添加以下内容:

/* Fire the change event */
 if ($select[0].selectedIndex != $(this).attr('index')) {
     $select[0].selectedIndex = $(this).attr('index');
    $($select[0]).trigger('change');
 }

第一组规则可能会覆盖第二组规则。试着评论第一个if语句。谢谢你的回复。我对第一个if语句进行了注释。但它仍然不起作用。然后再评论一下。这是一段原始代码,所以应该留在那里!嘿,看这又是一个黑客!在jqtransform.js代码中。注释此行:if($select.hasClass('jqTransfermHidden'){return;},然后在“onchange”事件运行之后:$('#容器选择').jqTransSelect();我有一个类似的问题,下面是一个对我有用的答案:[1]: