2009-09-01 23 views
0

我正在爲我的應用程序使用JQuery和cakephp。JQuery中的用法引用

I have created a select input Element using 

    $(document).ready(function(){ 
      $("#"+<?=$r['Attribute']['id'];?>).each(function() { 
      type= "<?=$r['Attribute']['type'];?>"; 
      attribute_id= "<?=$r['Attribute']['id'];?>"; 
        if(type=="dropdown") 
        { 
        var ht = $.ajax({ 
           type: "GET", 
           url: "http://localhost/FormBuilder/index.php/forms/viewChoices/" 
           + attribute_id, 
           async: false 
          }).responseText; 
         var myObject = eval('(' + ht + ')'); 

     var data = myObject;var j=0; 
     $.map(data.choices, function(i){ j++; alert(i.choice); 
     $('<option value='+i.choice+'>'+i.choice+'</option>') 
       .appendTo("#"+<?=$r['Attribute']['id'];?>); 
      return i.choice;}); 
      } 
     });   
    }); 

而創建就像一個,,

<select id="10" name="Experience"> 
     <option value="Fresher">Fresher</option> 
     <option yrs="" 5="" value="Below">Below 5 Yrs</option> 
     <option yrs="" 10="" value="Above">Above 10 yrs</option> 
    </select> 

我不知道爲什麼值未設置像

 <option value="Below 5 Yrs">Below 5 Yrs</option> 

請建議我...我知道有一些問題在引號中,我嘗試了很多選項...

+0

什麼是** ** HT返回(原始輸出)? – TheVillageIdiot 2009-09-01 07:20:39

回答

2

您應該使用

$('<option value="'+i.choice+'">'+i.choice+'</option>') 

因爲當你這樣做的第一種方式,它返回的HTML:

<option value=Below 5 Yrs>Below 5 Yrs</option> 

,瀏覽器將其視爲

<option yrs="" 5="" value="Below">Below 5 Yrs</option>