PrototypeJS -克隆输入,保留复选框,即使在Firefox中removeAttribute

PrototypeJS - Cloning Input, Retains Checkboxes Even After removeAttribute in Firefox

本文关键字:Firefox removeAttribute 复选框 -克 输入 保留 PrototypeJS      更新时间:2023-09-26

我正在克隆一行,更改元素中的一些内容,然后将元素输出到页面。问题是,当我删除选中的属性时,它在IE中工作得很好,但FF保留了克隆的原始元素的选中状态。

例如:

var newHTML = $$('.importRow')[0].clone(true);
$(newHTML).select('input').each(function(s, index) {  
   $(s).removeAttribute('checked'); //This is to remove any checked value
   if ($(s).hasClassName('someClass') && $(s).getValue() == 'someValue'){ //This is to assign a new default checked value
      $(s).setAttribute('checked','checked');
   }
}
$(this).up().insert({ 
   before: newHTML 
});

我该如何解决这个问题,使FF不保留先前选择的值?

编辑:

返回元素,它正确地显示了它,但是Firefox由于某种原因记住了这个值,我不确定如何覆盖这种行为。

尝试使用复选框DOM attributes: s.checked = false; s.defaultChecked = false;,或者,不删除checked属性,将其值设置为false: s.writeAttribute('checked', 'false');

顺便说一下,一旦一个元素被原型函数扩展,你不需要重复调用$();