在iframe中获取单选值

在iframe中获取单选值

问题描述:

我该如何使用jQuery做到这一点?

How do I go about doing this with jQuery?

基本结构:

<form id="myForm">
  <iframe>
    <!-- Normal HTML headers omitted -->
    <input type=radio name="myRadio" value=1>First
    <input type=radio name="myRadio" value=2>Second
    <input type=radio name="myRadio" value=3>Third
  </iframe>
  <input type=button value="Submit" />
</form>

我从网上尝试了各种示例,例如

I tried various examples from the net such as

$("input[@type=radio][@checked]");

但是失败了.即使使用jQuery表单插件的 .fieldValue()也会失败.

But failed. Even with jQuery form plugin's .fieldValue() failed.

尝试$('#myForm iframe').contents().find('input[name=myradio]').val()

我假设iframe内容已经加载并且可以在同一个域中访问.

I'll assume that the iframe contents have already been loaded and are accessible e.g same domain.