0

我想在 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 ???

4

4 回答 4

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');
于 2013-11-01T10:28:03.143 回答
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');

于 2013-11-01T10:33:24.047 回答
0

JS

var elem = window.frames[0].document.getElementById('student_name');
personalData['childname'] = elem.options[elem.selectedIndex].id;

jsfiddle 演示

于 2013-11-01T10:46:32.553 回答
0

尝试这个:

personalData['childname']=window.frames[0].document.getElementById('student_name').getAttribute("id");
于 2013-11-01T10:29:12.750 回答