I am trying to get the values from my select list on a jquery mobile app.
Here is my select markup:
<div data-role="fieldcontain">
<label for="stuff" class="select">Stuff:</label>
<select name="stuff" id="stuff" multiple="multiple">
<option value=''>Select One</option>
<option value="Stuff 1">Stuff 1</option>
<option value="Stuff 2">Stuff 2</option>
<option value="Stuff 3">Stuff 3</option>
<option value="Stuff 4">Stuff 4</option>
<option value="Stuff 5">Stuff 5</option>
<option value="Stuff 6">Stuff 6</option>
</select>
</div>
How do I get the ma separated string of values from this multiselect
I am trying to get the values from my select list on a jquery mobile app.
Here is my select markup:
<div data-role="fieldcontain">
<label for="stuff" class="select">Stuff:</label>
<select name="stuff" id="stuff" multiple="multiple">
<option value=''>Select One</option>
<option value="Stuff 1">Stuff 1</option>
<option value="Stuff 2">Stuff 2</option>
<option value="Stuff 3">Stuff 3</option>
<option value="Stuff 4">Stuff 4</option>
<option value="Stuff 5">Stuff 5</option>
<option value="Stuff 6">Stuff 6</option>
</select>
</div>
How do I get the ma separated string of values from this multiselect
Share Improve this question asked Jan 24, 2012 at 14:36 lodkkxlodkkx 1,1732 gold badges17 silver badges29 bronze badges2 Answers
Reset to default 6You can try to use jquery val()
method to retreive array of selected values and join
method to bine them:
var maSeparatedValues = $("#stuff").val().join(",");
Simple use jquery val
method:
var vals = $('#stuff').val(); // Array, e.g. ["Stuff 2", "Stuff 3"]
console.log(vals.join(',')); // String 'Stuff 2,Stuff 3'
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745295673a4621126.html
评论列表(0条)