简体   繁体   English

通过选中的单选按钮禁用TextBox?

[英]Disable TextBox by checked Radio Button?

i created some javascript to disable input textbox when a radio button is checked and it works fine in firefox but in IE it doesn't work? 我创建了一些JavaScript以在选中单选按钮时禁用输入文本框,并且在Firefox中可以正常工作,但在IE中不起作用? What Can i Do? 我能做什么?

the example 这个例子

function display_input(inputvalue)
{
    if(inputvalue == '1')
    {
        document.getElementById('time11').disabled = true;
        document.getElementById('time12').disabled = true;
        document.getElementById('date2').disabled = true;
    }
    else if(inputvalue == '2')
    {
        document.getElementById('time11').disabled = false;
        document.getElementById('time12').disabled = false;
        document.getElementById('date2').disabled = false;
    }

}

It's possible that IE doesn't run the code until the checkbox that was checked loses input focus. 在选中的复选框失去输入焦点之前,IE可能不会运行代码。 This is, I believe, how IE operates its onchange method. 我相信这就是IE如何操作其onchange方法。 At the end of your display_input() function, try calling blur() on the checkbox: display_input()函数的末尾,尝试在复选框上调用blur()

function display_input(inputvalue)
{
  if(inputvalue == '1')
  {
    document.getElementById('time11').disabled = true;
    document.getElementById('time12').disabled = true;
    document.getElementById('date2').disabled = true;
  }
  else if(inputvalue == '2')
  {
      document.getElementById('time11').disabled = false;
      document.getElementById('time12').disabled = false;
      document.getElementById('date2').disabled = false;
  }
  // Blur focus on the checkbox...
  document.getElementById('theCheckBoxId').blur();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM