在mootools或javascript中为标签标签设置htmlFor属性

时间:2011-05-15 08:04:49

标签: javascript dom mootools

我想通过此命令在mootools 1.3中创建一个新标签:

new Element('lable', {
    'for':'chk_id',
    'html':'hello'
  }).inject(document.body);

标签将使用“hello”文本创建,但“for”属性不适用于标签。 我测试'htmlFor'属性,我可以在firebug中看到这个属性,但它不起作用(我想检查输入id ='chk_id')。 在mootools或javascript中有什么解决方案吗?

1 个答案:

答案 0 :(得分:1)

也许使用label而非法语lable可能是一个好的开始。 只需确保for属性与input元素的id匹配即可。

new Element("label[for=bar][text=bar]").inject(document.body);

在1.3 :) http://jsfiddle.net/Fw9hh/

中很好
相关问题