以编程方式访问对象财产

我有一个活动,服务人员可以在网上注册.这是两天的事件.我希望能够禁用相同的实验室day2当它被选中在第1天(所以服务员不选择相同的实验室在两个不同的天).这个功能我用……[HTML]函数DisableOther (a) {var myD = a.name.substring (4、5);var myS = a.name.substring (6、7);var othD;如果(myD = = 1) {othD = ' 2 ';其他}{othD = ' 1 ';}var b = eval ("document.frm01."+ a.name);var c = findButton (b);eval (+ othD +"S"+"document.frm01.optD"myS +"("c + +").禁用= true");如果(c = = 0) {eval (+ othD +"S"+"document.frm01.optD"myS +"(" + (c + 1) + "].禁用= false");其他}{eval (+ othD +"S"+"document.frm01.optD"myS +"(" + (c - 1) + "].禁用= false");}}函数findButton (buttonGroup) {(我= 0;我如果(buttonGroup[我].检查= = true) {返回我;}}}[/ HTML]我知道我不应该使用eval但我不知道如何访问单选按钮组的属性.上面的代码在IE但不是在FF,任何想法?谢谢……

# 回答1

嗨……是的:)…你不应该和不必使用eval……看一看下面的例子:

选择 | 换行 | 行号
  1. // we have a part of your id
  2. var id = 'optD1S';
  3.  
  4. // now we make the correct id (optD1S1)
  5. var node_id = id + 1;
  6.  
  7. // refer to the node with node_id
  8. var node = document.getElementById(node_id);
  9.  
  10. // setting the disabled attrib to disabled
  11. node.setAttribute('disabled', 'disabled');
  12.  
  13. // remove the attrib
  14. node.removeAttribute('disabled');
  15.  

亲切的问候

标签: Javascript

添加新评论