2014-02-26 68 views
0

單選按鈕無法正常工作。在第一部分中,從控制器創建下拉列表,並在更改下拉列表項時返回$ .json列表,我希望將每個列表項目顯示爲無線電按鈕label.Following是我的代碼從jquery創建單選按鈕

<div class="col9 last"> 
     @Html.DropDownList("PaymentModelddl", new SelectList(listItems, "Value", "Text")) 
    </div 
<div class="col9 right last" id="PlanNames"> 

      </div> 



<script> 
$(document).ready(function() { 
    $('#PaymentModelddl').change(function() { 

     var ModelValue = $(this).val(); 
     //alert(ModelValue+""); 
     if (ModelValue > 0) { 
      $.getJSON('/AccountInfoTemp/TestJSON/' + ModelValue, function (result) { 
       var ddl = $('#PlanNames'); 
       ddl.empty(); 
       var d = ""; 
       $(result).each(function() { 
        d += "<input type='radio' name='radio' style='display:block; float:left;' />" 
         + "<span class='label'>" + this.Name + "</span><div class='clear'></div>"; 
       }); 

       d += "" 
       ddl.html(d); 
      }); 
     } 
    }); 

}); 

回答

0

嘗試用$.each()

$.each(result, function(idx, item) { 
    d += "<input type='radio' name='radio' style='display:block; float:left;' />" 
     + "<span class='label'>" + item.Name + "</span><div class='clear'></div>"; 
});