首页 \ 问答 \ 单选按钮(INPUT type =“radio”)的OnChange事件处理程序不能作为一个值(OnChange event handler for radio button (INPUT type=“radio”) doesn't work as one value)

单选按钮(INPUT type =“radio”)的OnChange事件处理程序不能作为一个值(OnChange event handler for radio button (INPUT type=“radio”) doesn't work as one value)

我正在寻找一个通用的解决方案。

考虑2个具有相同名称的无线电类型输入。 提交时,检查的值决定了以下形式发送的值:

<input type="radio" name="myRadios" onchange="handleChange1();" value="1" />
<input type="radio" name="myRadios" onchange="handleChange2();" value="2" />

当单选按钮被取消选择时,更改事件不会触发。 因此,如果已经选择了值为“1”的无线电,用户选择了第二个,则handleChange1()不会运行。 这给我一个问题(对我来说),因为没有事情可以抓住这个去选择。

我想要的是复选框组值的onchange事件的解决方法,或者检测不仅当检查无线电时,还检测无线检测时的oncheck事件。

我确信你们中有些人以前遇到这个问题。 什么是一些解决方法(或理想情况下,正确的方法来处理)? 我只想捕捉更改事件,访问先前检查的收音机以及新检查的收音机。

PS
onclick似乎是一个更好的(跨浏览器)事件来指示何时检查收音机,但仍然无法解决未检查的问题。

我想这是有道理的,为什么一个复选框类型的替换在这种情况下可以工作,因为它在您检查或取消检查时更改其提交的值。 我希望单选按钮的行为更像是一个SELECT元素的onchange,但你能做什么?


I'm looking for a generalized solution for this.

Consider 2 radio type inputs with the same name. When submitted, the one that is checked determines the value that gets sent with the form:

<input type="radio" name="myRadios" onchange="handleChange1();" value="1" />
<input type="radio" name="myRadios" onchange="handleChange2();" value="2" />

The change event does not fire when a radio button is de-selected. So if the radio with value="1" is already selected and the user selects the second, handleChange1() does not run. This presents a problem (for me anyway) in that there is no event where I can can catch this de-selection.

What I would like is a workaround for the onchange event for the checkbox group value or alternatively an oncheck event that detects not only when a radio is checked but also when it is unchecked.

I'm sure some of you have run into this problem before. What are some workarounds (or ideally what is the right way to handle this)? I just want to catch the change event, access the previously checked radio as well as the newly checked radio.

P.S.
onclick seems like a better (cross-browser) event to indicate when a radio is checked but it still does not solve the un-checked problem.

I suppose it makes sense why onchange for a checkbox type does work in a case like this since it changes the value that it submits when you check or un-check it. I wish the radio buttons behaved more like a SELECT element's onchange but what can you do...


原文:https://stackoverflow.com/questions/8838648
更新时间:2022-05-08 16:05

最满意答案

我能弄清楚这个问题。 在Ubuntu上,Docker将容器的DNS服务器设置为8.8.8.x的Google服务器。 据了解,这是Ubuntu的一个解决方法,因为Ubuntu将/etc/resolv.conf设置为127.0.0.1。

这些Google服务器无法从防火墙后面访问,这就是为什么我们无法解析任何URL。

这个修复是告诉Docker要使用的DNS服务器。 这个修复取决于你如何安装Docker:

Ubuntu软件包

如果您安装了Ubuntu软件包,请编辑/ etc / default / docker并添加以下行:

DOCKER_OPTS="--dns <your_dns_server_1> --dns <your_dns_server_2>"

您可以添加尽可能多的DNS服务器,您想要这个配置。 编辑此文件后,您将需要重新启动Docker服务:

sudo service docker restart

二进制

如果您已经通过二进制文件方法安装了Docker(即没有包),则在启动Docker守护程序时设置DNS服务器:

sudo docker -d -D --dns <your_dns_server_1> --dns <your_dns_server_2> &

I was able to figure out the issue. On Ubuntu, Docker sets the DNS servers for container to Google's servers at 8.8.8.x. As I understand it, this is a workaround on Ubuntu due to the fact that Ubuntu sets /etc/resolv.conf to be 127.0.0.1.

Those Google servers weren't accessible from behind our firewall, which is why we couldn't resolve any URLs.

The fix is to tell Docker which DNS servers to use. This fix depends on how you installed Docker:

Ubuntu Package

If you have the Ubuntu package installed, edit /etc/default/docker and add the following line:

DOCKER_OPTS="--dns <your_dns_server_1> --dns <your_dns_server_2>"

You can add as many DNS servers as you want to this config. Once you've edited this file you'll want to restart your Docker service:

sudo service docker restart

Binaries

If you've installed Docker via the binaries method (i.e. no package), then you set the DNS servers when you start the Docker daemon:

sudo docker -d -D --dns <your_dns_server_1> --dns <your_dns_server_2> &

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)