从动态选择选项中获取文本(Get text from dynamic select option)
我有多个选择选项,我想在.texts上写文字car或motorcycle
这是一些动态选择选项
<td> <select id="area-0"> <option value="1">Car</option> <option value="2">Motorcycle</option> </select> </td> <td class="texts"></td> <td> <select id="area-1"> <option value="1">Car</option> <option value="2">Motorcycle</option> </select> </td> <td class="texts"></td>这是我的剧本
$('select[id^=area]').change(function(){ var text_t = $(this option:selected).text(); $(this).parent().next().html(text_t); });我怎么能把car或motorcycle放在.texts
I have more than one select option, i want to write text car or motorcycle on .texts
This a few dynamic select option
<td> <select id="area-0"> <option value="1">Car</option> <option value="2">Motorcycle</option> </select> </td> <td class="texts"></td> <td> <select id="area-1"> <option value="1">Car</option> <option value="2">Motorcycle</option> </select> </td> <td class="texts"></td>this my script
$('select[id^=area]').change(function(){ var text_t = $(this option:selected).text(); $(this).parent().next().html(text_t); });How can i place car or motorcycle on .texts
最满意答案
您可以使用.find()方法获取所选option的文本。 根据当前实现,您必须获得语法错误。
var text_t = $(this).find('option:selected').text();代替
var text_t = $(this option:selected).text();You can use .find() method to get the selected option's text. As per current implementation you must be getting syntax error.
var text_t = $(this).find('option:selected').text();instead of
var text_t = $(this option:selected).text();更多推荐
发布评论