我想将选项中的值传递给表。这是我的代码:
<select id="ListSujet" name="ListSujet">
<option value="514402,True">Copie de Musculation</option>
<option value="514430,True">Gecko Leopard</option>
</select>
但我想要接受价值&#34; True&#34;并把他放在桌子上:
<select id="ListSujet" name="ListSujet">
<option value="514402">Copie de Musculation</option>
<option value="514430">Gecko Leopard</option>
</select>
<td>True<td>
如何使用Jquery执行此操作?非常感谢
答案 0 :(得分:0)
$.each($("select").find("option"),function(){
var splitArr = $(this).val().split(",");
$(this).val(splitArr[0]);
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<select id="ListSujet" name="ListSujet">
<option value="514402,True">Copie de Musculation</option>
<option value="514430,True">Gecko Leopard</option>
</select>
&#13;
答案 1 :(得分:0)
试试这个:
$("#ListSujet option").each(function(){
var s = $(this).val().split(",");
$(this).val(s[0]);
//console.log($(this).val());
$("tr").append("<td>" + s[1] + "</td>");
});
$("#ListSujet").on("change",function(){
console.log($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="ListSujet" name="ListSujet">
<option value="514402,True">Copie de Musculation</option>
<option value="514430,True">Gecko Leopard</option>
</select>
<table>
<tr id="row">
</tr>
</table>