仅选择一个复选框(并取消选择其余部分),如果选中了复选框,则显示输入字段
我有一个带有“是”和“否”作为两个复选框的表单。这些最初是未经选择的。我希望用户只选择其中之一,如果他们不想做出决定,则可以选择取消选择(这就是我不使用单选按钮的原因)。选择“是”应取消选择“否”,反之亦然。我不知道该怎么做。我正在使用 PHP (codeigniter)、Javascript 和 JQuery。
其次,选择“是”或“否”后,需要显示一个输入字段。我已经有了这个设置,但它会切换“onclick”操作,这意味着选择“是”两次显示并隐藏输入字段!我希望输入字段在选择“是”或“否”时显示,如果未选择“是”和“否”则消失。
<块引用>$do_toggle = "onClick=\"javascript:toggle('togglenote');\""; echo form_radio('决定'.$key,'y',FALSE,$do_toggle)."是"; echo form_radio('决定'.$key,'n',FALSE,$do_toggle)."否"; 回显 form_input($mytext); // 我在上面的 form_input 周围放置了一个 div 标签 // 但它没有显示在 StackOverflow 问题中... // 但它的存在是为了让切换工作。
I have a form with "Yes" and "No" as two checkboxes. These come in unselected at first. I'd like the user to only select one of these with the option to deselect their choice if they don't want to make a decision (which is why I didn't use radio buttons). Selecting Yes should deselect No and vice versa. I'm not sure how to do this. I'm using PHP (codeigniter), Javascript and JQuery.
Secondly, after either Yes or No is selected, an input field needs to be displayed. I've got this setup but it toggles on the "onclick" action, which means selecting Yes twice shows and hides the input field! I want the input field to show if Yes or No are selected and disappear if the both Yes and No are unselected.
$do_toggle = "onClick=\"javascript:toggle('togglenote');\""; echo form_radio('decision'.$key,'y',FALSE,$do_toggle)."Yes "; echo form_radio('decision'.$key,'n',FALSE,$do_toggle)."No"; echo form_input($mytext); // I put a div tag around the form_input above // but it's not showing in the StackOverflow question... // but it's there for the toggle to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设你的 html 是这样的(我认为是这样):
你的 js 是:
希望这有帮助。干杯。
Assuming your html is like this (i think it is):
Your js would be:
Hope this helps. Cheers.
这应该做你想要的:
This should do what you want:
附言。 JQuery 无法在我的诺基亚 6303c :) 设备上工作,硬编码 - 可以工作......所以应用程序必须有 2 个部分。
PS. JQuery works not at my nokia 6303c :) device, hard coded - will work ... so application must have 2 parts.