簡體   English   中英

JQuery mobile - 如何設置多選的值?

[英]JQuery mobile - how to set the values of a multiple select?

我在jquery mobile中有一個多選。

docs: http//jquerymobile.com/demos/1.0a4.1/docs/forms/forms-selects.html

為了獲得價值,我這樣做

    var leerplandoelen = $("#AddLessonForm_leerplandoelen").val();

        var leerplandoelenString = "";
        if(leerplandoelen != null){
            $.each(leerplandoelen, function(i, le){
                if(i!=leerplandoelen.length-1){
                    leerplandoelenString += "\""+le+"\",";
                }else{
                    leerplandoelenString += "\""+le+"\"";
                }
            });
        }

得到像這樣的字符串'“1”,“2”,“3”'。

我該如何設置值?

我嘗試了以下方法:

    $('#AddLessonForm_leerplandoelen').val(['3','6','14']).selectmenu('refresh');

但它沒有用。

這樣做,讀取所選項目的數組。 根據value選擇標記選項

// array of values
var selected = ["2", "4"];

$.each(selected, function (i, v) {

  // mark options selected
  $("select option[value='" + v + "']").prop("selected", true);

  // refresh selectmenu
  $("select").selectmenu("refresh");

});

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM