2013-01-16 27 views
0

不工作我試圖做的是把一些元素在選擇列表中,如果這些元素在它尚未功能。我的頭被設置爲ISO編碼,但如果我的「主題」包含一個貨幣符號,如「€」,我得到一個問號「?」而不是列表中。encodeURIComponent方法在選擇列表

這裏是我的代碼:

  $.each(subjects, function(key, subject) 
     { 
      if (select.find('option[value=\"' + subject + '\"]').length === 0 && subject!="") 
      { 
       /*if (selectList == "produitcartesien") 
        { 
         alert(subject); 
        }*/ 
       //Ajouter la nouvelle catégorie dans la liste 
        $('<option>', { 
        value: subject, 
        text: subject 
        }).appendTo(select); 

       if (colored==true && !(selectionOf("subjectslist")=="" && selectionOf("relationslist")=="" && selectionOf("complementslist")=="" 
         && selectionOf("subjectCategories")=="" && selectionOf("complementcategories")=="")) 
        { 

         $('#' + selectList + ' option[value="'+ subject +'"]').css('color', 'red'); 
        } 
      } 
     }); 

我試圖

value: encodeURIComponent(subject); 
text: encodeURIComponent(subject); 

但它顯示與尷尬的字符,如2%2C3F科目... 我能做些什麼以顯示我的字符串貨幣符號? 預先感謝您。

編輯:對不起,上述問題是錯誤的。我的變量之前已經設置了問號。這是真正的問題,目前仍未得到答覆:https://stackoverflow.com/questions/14185309/use-encodeuricomponent-with-jsp

如果有人可以幫助... 謝謝。

+0

確保您在匹配ISO格式文件保存好也。順便說一句,那些「尷尬的角色」是[URL編碼(百分比編碼)](http://en.wikipedia.org/wiki/Percent-encoding) – Alexander

回答

0

你嘗試使用:

value: decodeURIComponent("50 %E2%82%AC"); 
text: decodeURIComponent("50 %E2%82%AC"); 

的結果將是「50€」

+0

的問題是,我的價值不是恆定的,而是變量。 在我的例子,該值爲2,38€,但它可能是一些其他的量或貨幣... 你的回答促使我嘗試decodeURIComponent(encodeURIComponent方法(主題)),但它也不能工作... – user1881815