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>
2022-08-30 13:08

满意答案

使用jQuery,您可以执行以下操作(当用户单击文本字段时,使用类radio禁用单选按钮):

$("#location").click(function(){
    $(".radio").prop("disabled", true);
});

现在,如果您需要启用单选按钮,如果用户单击外部(或以另一种方式离开文本字段)文本字段,您可以更改上面代码中的clickblur ,如下所示:

$("#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 to blur, like this:

$("#location").blur(function(){
    $(".radio").prop("disabled", false);
});

相关问答

更多

Rails应用程序单选按钮不会更新布尔字段(Rails application radio buttons do not update boolean field)

尝试在单选按钮上添加一个值: <%= f.radio_button :public, true, label: "Public", label_class: "whiteClass", value: true, inline: true, checked: true %> <%= f.radio_button :public, false, label: "Private (Only Paul will see)", label_class: "whiteClass", value: false,...

Radio Buttons jQuery(Radio Buttons jQuery)

您不能在具有相同ID的同一文档中包含两个元素。 您的选择器#companyreg正在查找第一个元素而不是第二个元素。 如果你要检查 $("#companyreg").length 你会看到1。 你可以通过使用来解决这个问题 $( '[id="companyreg"]' ) 虽然它不会修复你的无效文件。 最好的方法是删除ID并为这些元素添加一个类,然后通过该类选择。 我没有检查你的其余代码,看看这是否是唯一的问题,但我怀疑它是最大的问题。 You cannot have two elements...

如果未选中单选按钮,如何将隐藏字段设置为零(How to set hidden field to zero if radio buttons are not checked)

将零输入无线电置于循环之外(在它非常好之后,为了分配$n var)并使用额外的CSS来隐藏它: //loop here <input type="radio" id="hiddenRadio" name="ques['<?php echo $n; ?>'][]" value="0" checked /> <style> #hiddenRadio{ visibility: hidden; } </...

基于Shiny上的单选按钮选择禁用textInput(Disable textInput based on radio button selection on Shiny)

您可以在服务器上使用session$sendCustomMessage (它生成禁用或启用文本框的JavaScript)和UI(执行JavaScript)中的Shiny.addCustomMessageHandler来完成此操作。 library(shiny) ui <- fluidPage( tags$head(tags$script(HTML(' Shiny.addCustomMessageHandler("jsCode", function(message) ...

Textinput字段禁用单选按钮(Textinput field disables radio buttons)

使用jQuery,您可以执行以下操作(当用户单击文本字段时,使用类radio禁用单选按钮): $("#location").click(function(){ $(".radio").prop("disabled", true); }); 现在,如果您需要启用单选按钮,如果用户单击外部(或以另一种方式离开文本字段)文本字段,您可以更改上面代码中的click以blur ,如下所示: $("#location").blur(function(){ $(".radio").prop("...

没有任何单选按钮的ListPreferences?(ListPreferences without any radio buttons?)

当您自定义首选项时,这是可能的。当您仅使用首选项时,它就像一个按钮。之后您必须实现您想要的任何内容。以下示例只显示您的要求。当您单击首选项时,它会显示列表对话框没有单选按钮。但我没有实现将数据存储在共享首选项中。如果你想这样做,你必须实现自己的。我只是在这里发布一些代码。 prefereces=findPreference("intent"); // prefereces.setIntent(new Intent(Intent.ACTION_VIEW,Uri.parse("https...

使用单选按钮(jQuery)禁用/启用文本字段(Disable/enable text field with radio button (jQuery))

根据您的网站html完全更改。 这应该工作: $(document).ready( function(){ $('#casodhoda,#casprihoda').prop('disabled',true); $('input[type=radio][name=radioknof]').click( function(){ $('#casodhoda,#casprihoda').prop('disabled',true).val(''); $(this).next('spa...

如何根据单选按钮切换启用/禁用输入字段(How to toggle enable/disable input field based on radio button)

你可以这样做 $(document).ready(function(){ $("#text-inputt").prop('disabled', true); $('input[type=radio]').click(function(){ if($(this).prop('id') == "lastt"){ $("#text-inputt").prop("disabled", false); }else{ $("#te...

如何使用RadioSelect字段创建Django表单,并禁用某些按钮?(How to create a Django form with a RadioSelect field, and some buttons disabled?)

进一步的研究发现了一个事实,即RadioSelect renderer可以被替换 ,并作为参数传递给初始的widget创建功能。 所以我创建了自己的渲染器,并附上了一个布尔列表,指出应该禁用哪些单选按钮。 渲染器根据需要为每个单选按钮小部件添加一个禁用的属性,然后force_unicode将小部件的属性转换为包含disabled="True"值的HTML。 from django.utils.safestring import mark_safe from django.utils.encodin...

填充单选按钮?(Populating radio buttons?)

列的顺序在数据库中是什么并不重要...这与您选择字段的顺序无关。由于您首先选择lastName,您需要将$ row [1]替换为$ row [0 ]。 另外,尝试更改ID以使其唯一。 It doesn't matter what the order of the columns is in your database... it matters the order you're selecting the fields in. Since you first select lastName, yo...

相关文章

更多

Solr4.7---Field、CopyField、DynamicField

Field: Field就是一个字段,定义一个Field很简单: 基本上属性也和FieldType类似 ...

Solr Document [null] missing required field: id 的原因

在solr建立索引的时候,如果你提交的doc中没有 id 这个Field,结果Solr在建立索引时候出 ...

jquery1.4.4的radio选中项

var updkbval=$(&quot;input[name=sex][@checked]&quot ...

solr error logs org.apache.solr.common.SolrException: ERROR: [doc=17] unknown field alias

在solr中 添加新的索引词语时,报如标题所示错误,指定是插入的字段没有在solr索引字段里 可以修改 ...

solr required field: id

为了和以前的程序兼容,在solr建立索引的时候,将id设为gid,结果在建立索引时候出现如下错误: o ...

启动Solr时报 _version_ field must exist in schema 错误的解决方法

Solr启动时报 org.apache.solr.common.SolrException:org.a ...

elasticsearch 添加字段

Elasticsearch中的mapping一旦创建,就不能再修改。但是添加字段是可以的。其实很简单, ...

Solr boost某字段的特殊值

http://www.quora.com/Boosting-documents-in-solr-on- ...

jqgrid删除按钮出问题

jqgrid删除按钮出问题 我写的代码如下: function getGrid(){ // 定义 ...

最新问答

更多

Python / IPython奇怪的不可重现列表索引超出范围错误(Python/IPython strange non reproducible list index out of range error)

你得到IndexError的原因是你的输入文件显然不是完全用制表符分隔的。 这就是为什么当您尝试访问它时, splits[1]没有任何内容。 您的代码可以使用一些重构。 首先,你正在重复使用if -checks,这是不必要的。 这只是将cds0到7个字符,这可能不是你想要的。 我将以下内容放在一起,以演示如何重构您的代码,使其变得更加pythonic和干燥。 我无法保证它能够与您的数据集一起使用,但我希望它可以帮助您了解如何以不同的方式执行操作。 to_sort = [] # W

故事板从表格单元中延伸出来并显示其详细信息披露按钮(storyboard segue from a tablecell an its Detail Disclosure Button)

我不认为你可以链接一个特定的细节披露按钮瓦特/赛格。 我的故事板是非常程序化的B / C我使用了很多定制CGRect等。 所以我倾向于使用这样的东西: -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"ViewControllerIdentifer"

我们可以将Gherkin功能文件与testcomplete集成(Can we integrate Gherkin feature files with testcomplete)

TestComplete不支持Gherkin功能文件。 但是,TestComplete具有SDK,因此可以自己为此创建扩展。 TestComplete does not support Gherkin feature files. However, TestComplete has SDK so it is possible to create an extension for this by yourself.

TrustAllCertificatesCallback被忽略(TrustAllCertificatesCallback is ignored)

我没有做过这样的事情,但看看我认为可以看出错误的例子。 试试这个代码: static class Program { static void Main() { var tcpclient = new TcpClient("remote.example.com", 443); var tcpstream = tcpclient.GetStream(); var sslstream = new SslStream(tcpstream,

返回嵌套元素的索引(Return index of nested element)

您需要获取父li元素的索引。 否则,您将获得列表项内锚点的索引,该索引始终为零。 $(this.parentNode).index(); You need to get the index of the parent li element. Otherwise you are getting the index of the anchor inside the list item, which will always be zero. $(this.parentNode).index();

在数组中重新编号元素的有效方法(Efficient way of re-numbering elements in an array)

您需要多次迭代列表,我认为没有办法解决这个问题。 毕竟,在开始更改元素(第二遍)之前,首先必须确定不同元素的数量(第一遍)。 但是请注意,由于对index的重复调用而not in列表中具有O(n),因此可能具有最多O(n ^ 2)的不同元素的数量。 或者,您可以使用dict而不是value_map的list 。 字典比列表具有更快的查找速度,因此,复杂性应该确实在O(n)的数量级上。 您可以使用(1)字典理解来确定旧值到新值的映射,以及(2)用于创建更新子项的列表理解。 value_map =

Express app定义的`static`文件夹无法正常工作(Express app defined `static` folder not working properly)

选项1 你可以改变这一行: app.use( express.static(__dirname + '/puplic')); //my public folder. 至 app.use('/oneTime', express.static(__dirname + '/puplic')); //my public folder 选项2 我假设你在公共文件夹中有一个js文件夹,然后你需要更改你的HTML代码:

使用node.js和socket.io每秒广播一次(Using node.js and socket.io to broadcast every second)

对于计时器值,请在服务器端本身每秒更新本地计时器。 每当有任何用户进来时,给他这个值以及计时器的总值。 然后客户端将根据dandavis评论在本地启动自己的计时器,但在服务器端保留一些间隔,如15或10秒,服务器将广播当前计时器值,以便客户端相应地进行同步。 简而言之,服务器将每隔10(n:你决定)秒后广播,但它将在本地每秒更新定时器变量。 每当客户端进入时,它将获得总计时器值和当前计时器值。 广播当前出价的休息功能可以以正常方式完成。 For timer value, keep updatin

如何让XMLSerializer将命名空间添加到嵌套对象中的属性?(How do I get the XMLSerializer to add namespaces to attributes in nested objects?)

IXmlSerializable也许? 注意我还添加了(对A ): [XmlElement("A", Namespace = "http://www.example.com/namespace")] public TestSoapHeaderTypeValuePair A {...} 代码如下: public class TestSoapHeaderTypeValuePair : IXmlSerializable { private string _type; private