使用jQuery 1.2.3版本,我想补充后属性“最大长度” textarea元素节点,但它不工作:

$("textarea[@maxlength]").after("<b>Aint working</b>");

这是HTML代码:

<textarea maxlength="500">This is a test.</textarea>结果 <textarea maxlength="250">Yet another line.</textarea>结果 <textarea maxlength="125">Bar or foo, whatever.</textarea>

奇怪的是,如果更改与例如属性maxlength rel比它工作得很好!

检查出这个现实生活例如: http://www.host2000.be/_temp/jquery_tests_counter.html

PS:我知道的[@attribute]符号,因此不再在jQuery的1.3支持的,但是这无关的问题

有帮助吗?

解决方案

使用您的jQuery的版本,它仅适用于一个小窍门。 textarea的隐含价值有不同的浏览器不同的值。火狐,例如具有-1隐含值。

所以,为了你的脚本在Firefox上工作,你需要做到以下几点:

$("textarea[@maxlength!=-1]").after("<b>Aint working</b>");

这里你可以找到约maxlength属性的隐含值的详细信息。

享受!

scroll top