-2
<input type="radio" name="radiobutton" id="1_1 value="1. Жетоны" "/>
<select id="1_1" onchange="document.GetElementById(this.id).checked=true;">

当我更改选项时select,怎么会radio没有选中?

谢谢细心!但是还有其他问题,因为它也不起作用:

<input type="radio" name="radiobutton" id="1_1" value="1. Жетоны" "/>
<select name="1_1" onchange="document.GetElementById(this.name).checked=true;">

感谢沙希!

4

3 回答 3

2

有两件事是错误的:
- 您的input标签是无效的 HTML - 它缺少属性值的右双引号id,并且您在标签末尾有一个不合适的双引号。
- 看起来您正在尝试对inputandselect标记使用相同的 id。你不能那样做;他们的ID必须不同。

于 2013-08-06T00:43:07.883 回答
1

代替,

document.GetElementById(this.id)document.getElementById(this.id);

https://developer.mozilla.org/en-US/docs/Web/API/document.getElementById

于 2013-08-06T00:52:44.857 回答
0

元素 ID 在页面中必须是唯一的,但元素名称可以重复。此外,表单控件必须有一个名称才能成功(即提交给服务器)。

因此,您可以通过使用对表单控件的引用(并修复标记)来解决问题:

<form>
  <input type="radio" name="radiobutton" id="1_1" value="1.blah">
  <select name="whatever" id="1_1" onchange="this.form.radiobutton.checked=true;">
   <option>0
   <option>1
  </select>
  <input type="reset">
</form>

请注意,您需要一个重置按钮,否则无法在不重新加载页面(或用户运行脚本)的情况下取消选中单选按钮。

于 2013-08-06T01:36:35.447 回答