Textinput字段禁用单选按钮(Textinput field disables radio buttons)
我确信有很多方法可以做到这一点,但我想找到最简单的方法,最好是基于CSS。
我有一个简单的表单,有四个单选按钮,后跟一个文本字段。 如果用户在文本字段中单击,我需要禁用单选按钮。 这是我的基本代码,并且授予,我仍在学习表单,因此可能存在其他错误:
<div class="left-column"> <input type="radio" class="radio" name="location" value="address-1" id="address-1" checked="checked" /> <label for="address-1">First location</label> <input type="radio" class="radio" name="location" value="address-2" id="address-2" /> <label for="address-2">Second location</label> </div> <div class="right-column"> <input type="radio" class="radio" name="location" value="address-3" id="address-3" /> <label for="address-3">Third location</label> <input type="radio" class="radio" name="location" value="address-4" id="address-4" /> <label for="address-4">Fourth location</label> </div> <div> <textarea id="location" type="text" tabindex="1" name="location" cols="22" rows="1"> </textarea> </div>
I'm sure there are many ways to do this, but I'd like to find the simplest way, preferably CSS-based.
I have a simple form with four radio buttons followed by a text field. I need to disable the radio buttons if the user clicks in the text field. This is my basic code, and granted, I'm still learning about forms, so there may be other errors:
<div class="left-column"> <input type="radio" class="radio" name="location" value="address-1" id="address-1" checked="checked" /> <label for="address-1">First location</label> <input type="radio" class="radio" name="location" value="address-2" id="address-2" /> <label for="address-2">Second location</label> </div> <div class="right-column"> <input type="radio" class="radio" name="location" value="address-3" id="address-3" /> <label for="address-3">Third location</label> <input type="radio" class="radio" name="location" value="address-4" id="address-4" /> <label for="address-4">Fourth location</label> </div> <div> <textarea id="location" type="text" tabindex="1" name="location" cols="22" rows="1"> </textarea> </div>
满意答案
使用jQuery,您可以执行以下操作(当用户单击文本字段时,使用类
radio
禁用单选按钮):$("#location").click(function(){ $(".radio").prop("disabled", true); });
现在,如果您需要启用单选按钮,如果用户单击外部(或以另一种方式离开文本字段)文本字段,您可以更改上面代码中的
click
以blur
,如下所示:$("#location").blur(function(){ $(".radio").prop("disabled", false); });
With jQuery, you can do something like this (which disables the radio buttons with class
radio
when the user clicks into the text field):$("#location").click(function(){ $(".radio").prop("disabled", true); });
Now if you need to enable the radio buttons if the user clicks outside (or in another way leaves the text field) the text field, you could just change
click
in the code above toblur
, like this:$("#location").blur(function(){ $(".radio").prop("disabled", false); });
相关问答
更多Rails应用程序单选按钮不会更新布尔字段(Rails application radio buttons do not update boolean field)
Radio Buttons jQuery(Radio Buttons jQuery)
如果未选中单选按钮,如何将隐藏字段设置为零(How to set hidden field to zero if radio buttons are not checked)
基于Shiny上的单选按钮选择禁用textInput(Disable textInput based on radio button selection on Shiny)
Textinput字段禁用单选按钮(Textinput field disables radio buttons)
没有任何单选按钮的ListPreferences?(ListPreferences without any radio buttons?)
使用单选按钮(jQuery)禁用/启用文本字段(Disable/enable text field with radio button (jQuery))
如何根据单选按钮切换启用/禁用输入字段(How to toggle enable/disable input field based on radio button)
如何使用RadioSelect字段创建Django表单,并禁用某些按钮?(How to create a Django form with a RadioSelect field, and some buttons disabled?)
填充单选按钮?(Populating radio buttons?)
相关文章
更多Solr4.7---Field、CopyField、DynamicField
Solr Document [null] missing required field: id 的原因
jquery1.4.4的radio选中项
solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias
solr required field: id
启动Solr时报 _version_ field must exist in schema 错误的解决方法
elasticsearch 添加字段
Solr boost某字段的特殊值
jqgrid删除按钮出问题
Mysql字段操作—增加字段、删除字段、修改字段名、修改字段类型(约束条件)
最新问答
更多Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)
故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)
我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)
TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)
返回嵌套元素的索引(Return index of nested element)
在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)
Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)
Javascript错误:未捕获TypeError:无法读取null的属性'value'[duplicate](Javascript error: Uncaught TypeError: Cannot read property 'value' of null [duplicate])
使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)
如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)
Copyright ©2023 656463.com All Rights Reserved.滇ICP备2022006988号-50
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们,本站将尽快处理。谢谢合作!