【问题标题】:Change DIV content one after another on button click if the radio button inside that DIV is checked如果选中 DIV 内的单选按钮,则在单击按钮时依次更改 DIV 内容
【发布时间】:2011-10-22 13:30:49
【问题描述】:

请帮我解决这个问题,我处于中间状态,无法继续进行,因为我的代码效率低下且无法理解...
我有一系列代码,如下所示..

     var codes=[["header1","<input type='radio'>","option2","option3"],["header2","<input type='radio'>","option5","option6"],["header3","<input type='radio'>","option8","option9"]];

否则请检查此小提琴以检查我的进度...
http://jsfiddle.net/FgVGR/1/
在我的 HTML 中,我将有 3 个 DIV 标签

  DIV(class name="headerHolder") -- This is to hold header text from the array.
  DIV(class name="optionHolder") -- This contains the options related to each header displayed(Options will be next to the header element[index 0]).
  DIV Options contains options and radio button. 
  DIV(class name="navigation") with next button with ID "next" and back button with id "back".

基本上 DIV 将与第一个数组元素一起显示,即 headerHolder 中的 Header1 和单选按钮,option2 和 optionHolder DIV 中的选项 3。如果单击单选按钮并单击下一步按钮,则下一个数组元素,即以 header2 开头的元素将是显示在 headerHolder 和 optionHolder 中。检查单选按钮是移动到下一个数组的资格。如果单击后退按钮,则当前数组的上一个数组项应与上一个给定的单选按钮响应一起显示... optionHolder 中的选项应显示在两列中。目前我正在使用标签但无法显示..
请帮我解决这个问题...这就是我想要做的......

【问题讨论】:

  • 当你半途而废时,很难理解你想要什么。

标签: javascript jquery


【解决方案1】:

试试这个jsFiddle。这是我认为你想要的那样工作吗?

【讨论】:

  • 嗨 Max,感谢您的回复...但即使我没有选择单选按钮,它也能让我继续前进。
【解决方案2】:

据我了解 - 如果您的收音机被选中,您想要测试的每次向前点击。如果选中继续前进。

为此,我会为所有单选按钮分配一个公共 id 或类(或为父容器分配一个并通过父子元素访问单选)。

然后在每次#next 单击时检查收音机的选中属性。如果选中则继续,如果未选中则返回。

这里又快又脏。你抓住 optionHolder。然后是其子 li 元素。然后是收音机。接下来我们提醒它的检查状态。

var radio = $("#optionHolder").children("li").children("input[type=radio]");
alert(radio.is(':checked'));

看看这个。 check radio buttons and fields to enable link

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-10
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-22
    相关资源
    最近更新 更多