jQuery .attr()似乎区分大小写 [英] jQuery .attr() seems to be case sensitive
问题描述
我有一个 select
元素,其中包含很少的自定义属性,我用它来动态验证它并显示相应的消息。属性的名称是驼峰式的,如
I have a select
element with few custom attributes that I use to validate it on the fly and display appropriate messages. Attribute's name is camel cased as in
<select validationMessage="Must select something" ... >...
问题是在jQuery版本中早于1.6 .attr()
似乎区分大小写。更有问题的是,它不会获取原始的套接字属性。这在Firefox中的Firefox中也是如此,但在Internet Explorer中按预期工作(不应该不区分大小写)。有趣的是,任何套管(原始套管除外)都有效。
The problem is that in jQuery version older than 1.6 .attr()
seems to be case sensitive. What's even more problematic, that it won't fetch originally cased attributes. This works the same in Firefox in Chrome, but works as expected (case insensitive as it should be) in Internet Explorer. It's also interesting that any casing (except original one) works.
这是一个 JSFiddle示例这个问题。您可以在左侧更改jQuery lib版本,然后点击运行以查看它如何与其他版本一起使用。
Here's a JSFiddle example of this issue. You can change jQuery lib version on the left and hit "Run" to check how it works with other versions.
我如何缓解此问题?
推荐答案
如果用以下内容替换 attr()
javascript等价 getAttribute()
,它似乎不区分大小写。
If you replace attr()
with the javascript equivalent getAttribute()
, it seems to not be case sensitive.
唯一的缺点是你必须 get()
首先是js对象:
The only drawback is that you have to get()
the js object first :
sel.get(0).getAttribute (validationMessage)
这篇关于jQuery .attr()似乎区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!