简体   繁体   中英

Not able to set value of drop down in jquery mobile

I am setting the value in drop down But it in not inserting .Why ? But same thing i do in another example i am getting the result.

 <div data-role="fieldcontain">
                        <label for="text-12" style="text-align:left;margin-left: 0px;"> Font Type:</label>
                        <select name="select-choice-1" id="select-choice-1" class="fontFamily_h">
                            <option>Select Font </option>
                            <option value="AntiquaAntiqua">AntiquaAntiqua</option>
                            <option value="Arial">Arial </option>
                           <option value="Times New Roman">Times New Roman</option>

                        </select>
                    </div>
<div data-role="fieldcontain">
                        <label for="text-12" style="text-align:left;margin-left: 0px;">Font Size:</label>
                        <select name="select-choice-1" id="select-choice-2" class="fontSize_h">Select Size
                            <option>Select Size</option>
                            <option value="9">9 px</option>
                            <option value="10">10 px</option>
                            <option value="11">11 px</option>
                            <option value="12">12 px</option>
                            <option value="13">13 px</option>

                        </select>
                    </div>


    $(document).on('click', '.default_h', function(event) {
       var i =12;
        alert("Hi"+ $('#select-choice-2').val()); getting select Size
       $('#select-choice-1').val('Arial').selectmenu("refresh");
       $('#select-choice-2').val('12 px').selectmenu("refresh");
        alert("Hi"+ $('#select-choice-1').val());  getting Arial
           alert("Hi"+ $('#select-choice-2').val());;getting select Size


});   

I am getting Arrial But in second example i am not getting 12 px

You need to set the val() property to the actual value attribute , not the text :

$('#select-choice-1').val('Arial').selectmenu("refresh");
$('#select-choice-2').val('12').selectmenu("refresh");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM