2013-01-17 27 views
0

我對錶單字段使用jqtransform。當我將動態字段添加到表單時,jqtransform不適用於新字段。 請參閱samplecode,jqtranform不適用於動態添加的字段

$(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> 

我試過了question給出的答案[請參見注釋行「新增」。但是這個解決方案對我來說也不起作用。 請做必要的。由於

+0

我也有類似的問題,這裏是一個答案爲我工作:http://stackoverflow.com/questions/8900367/jqtransform-select-ajax-update/9392412 [1]:http://stackoverflow.com/questions/8900367/jqtransform-select-ajax -update/9392412 – Vincent

回答

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'); 
} 
+0

我試過上面的解決方案。但沒有改變。 – lifeline

+0

第一組規則可能會覆蓋第二組規則。嘗試評論第一條if語句。 –

+0

謝謝你的回覆。我評論了第一條if語句。它仍然沒有工作。 – lifeline