我希望在javascript中选择选项ID,
personalData['childname']=window.frames[0].document.getElementById('student_name').value;
HTML ::
<tr>
<td align="right" width="40%"><label for="student" class="student" data-icon="">Select Name</label></td>
<td><select class="field" id="student_name" required="required" >
</select></td>
</tr>
**动态加载值**
此行给出了值,如何获得所选选项的id ???
答案 0 :(得分:1)
未经测试
var $select = $('#student_name', window.frames[0].document);
var id = $select.find('[value="' + $select.val() + '"]').attr('id');
或
var id = $('#student_name option:selected', window.frames[0].document).attr('id');
答案 1 :(得分:0)
试试这个:
personalData['childname']=window.frames[0].document.getElementById('student_name').getAttribute("id");
答案 2 :(得分:0)
尝试
javascript:
personalData['childname']=window.frames[0].document.getElementById('student_name').id;
jQuery:
personalData['childname']=$('#student_name option:selected',
window.frames[0].document).attr('id');
答案 3 :(得分:0)
纯JS
:
var elem = window.frames[0].document.getElementById('student_name');
personalData['childname'] = elem.options[elem.selectedIndex].id;