如果选择第一个 TD,则禁用一行中的所有其他 TD
我有一个包含多行的表。每行包含 5 列(或 5 个 TD)。第一个 TD 内部是一个文本字段和一个选择框。其他 4 个 TD 每个都包含一个表,其中包含一组单选按钮。
<tr bgcolor=#ffffff>
<td valign=center>
<select name=player1>
<option>0</option>
<option>1</option>
</select>
<input type="text" id="PlayerLocal1" name=p1name size=20>
</td>
<td>
<table border=1>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td><input type=radio name=p1o1 value="1B">1B
<td><input type=radio name=p1o1 value="FO">FO
</tr>
</table>
</td>
</tr>
</table></td></tr>
基本上,我希望禁用其他 4 个 TD 中的每一个 TD 中的单选按钮,除非用户在文本字段中输入值或在选择字段中选择一个值。
我正在考虑向每个 TR 添加一个类,然后以某种方式遍历不是第一个 TD 的每个 TD 并删除禁用属性(以启用它),但我无法理解如何创建条件语句或是否我需要使用 Parent() 或 Siblings() 或其他东西来遍历。
快速澄清: 我的表有多行和多列(为了节省空间,我只显示了 2 个 TD,但其他 3 个 TD 看起来就像第 2 个)。例如,第二行中的player1和p1name1将是player2和p2name2。因此,如果第一行中的文本/选择发生更改,则不应启用所有行中的所有单选按钮 - 仅启用第一行中的单选按钮。
任何帮助表示赞赏!
I have a table that contains multiple rows. Each row contains 5 columns (or 5 TDs). Inside of the first TD is a text field and a select box. The 4 other TDs each contain a table that contains a set of radio buttons.
<tr bgcolor=#ffffff>
<td valign=center>
<select name=player1>
<option>0</option>
<option>1</option>
</select>
<input type="text" id="PlayerLocal1" name=p1name size=20>
</td>
<td>
<table border=1>
<tr>
<td>
<table border=0 cellspacing=0 cellpadding=0>
<tr>
<td><input type=radio name=p1o1 value="1B">1B
<td><input type=radio name=p1o1 value="FO">FO
</tr>
</table>
</td>
</tr>
</table></td></tr>
Basically I want the radio buttons in each of the 4 other TDs disabled unless the user inputs a value in the text field OR selects a value in the select field.
I was thinking of adding a class to each TR, then somehow traversing each TD that isn't the first TD and removing the disabled attribute (to enable it), but I can't wrap my head around how create the conditional statement or whether I need to use Parents() or Siblings() or something else to traverse.
Quick Clarification:
My table has multiple rows and multiple columns (I only showed 2 of the TDs to save space, but the other 3 TDs looks just like the 2nd). For instance, player1 and p1name1 will be player2 and p2name2 in the second row. So, if the text/select is changed in the FIRST row, it shouldn't enable all radio buttons in ALL rows -- only radio buttons the FIRST row.
Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不过,我建议在属性周围加上引号,例如
name="p1name"
而不是name=p1name
。如果你不这样做,疯狂的事情就会发生。另外,当您指定元素 id 或类时,您可以更精确地确定哪些元素被选择,哪些没有被选择。举例来说,您只想禁用其中一个单选按钮,您可以轻松做到这一点,而如果没有 id,则要困难得多。
根据请求:
给选择和输入一个类,就像
你可以这样遍历:
如果你想在
的某处有更多单选按钮,而且您只想启用一个选定的组,同样,开设课程会很有帮助。您可以用类选择器替换
.find()
中的“input:radio”,并且只有那些选择器会受到影响。补充:
如果它们是页面上唯一的选择和文本输入,您也可以放弃添加类并使用类型选择器:
I would suggest putting quotes around attributes though, like
name="p1name"
rather thanname=p1name
. Crazy things can happen when you don't.Also, when you give elements id's or classes, you can be a bit more precise with which elements are selected and which aren't. Say, for example, you only wanted one of the radio buttons to be disabled, you could do that easily, whereas without the id, it's much more difficult.
As per request:
give the selects and input's a class, like
and you can traverse like this:
If you were to have more radio buttons somewhere in the
<tr>
, and you only wanted to enable a select group, again, having classes would be beneficial. You could substitute the class selector for the "input:radio" in the.find()
and only those would be affected.Addition:
If they''re the only selects and text inputs on the page, you could also forgo adding the classes and use type selectors instead:
您可以在这些 TD 周围放置一个 div,您可以使用 javascript 隐藏它们。在 google 上搜索将帮助您如何隐藏 div:)。祝你好运!
You could put a div around those TDs which you can hide using javascript. A search on google will help you how to hide divs :). Good luck!