0

我将 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 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>

我尝试了针对问题给出的答案[请参阅评论行“新添加”]。但该解决方案也不适用于我。请只做那些需要的。谢谢

4

1 回答 1

0

打开 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');
 }
于 2013-01-17T12:49:41.067 回答