jquery 中的 toString 方法?或类似的东西
找到答案了!
我正在阅读一个 xml 文档,并将其发送到一个
$(data).find('colleges').attr('next')
返回 discipline
的函数,并且 javascript 认为它是一个变量,我可以了解如何获取标签中的属性并将其作为字符串返回吗就像 'discipline'
是否有一个 toString() 类型的方法可以添加到选择中?
$(data).find('colleges').attr('next').toString()
我遇到的问题是,我将其发送到一个函数
createSelect( $(data).find('colleges').attr('next') )
,但 firebug 给我一个错误,说值、规则未定义?为什么 javascript 将纪律读取为 var 而不是字符串?
ANSWER FOUND!
I'm reading an xml document and I am sending this to a function
$(data).find('colleges').attr('next')
that returns discipline
and javascript is thinking it's a variable, can I some how get the attribute in the tag and have it return as a string like 'discipline'
Is there a toString()-type method that I could add onto the selection?
$(data).find('colleges').attr('next').toString()
The issue I am having is that I am sending that to a function
createSelect( $(data).find('colleges').attr('next') )
but firebug is giving me an error saying that the value, discipline, is undefined? Why is javascript reading discipline as a var and not a string?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
attr
函数返回一个字符串,您可以将其放入变量中。The
attr
function returns a string, which you can put into a variable.如果这...
...没有找到任何匹配项(
...
),那么这... ...将返回
undefined
。您应该做的第一件事是测试
.find()
是否找到任何内容。如果
警报
为您提供0
,则说明没有匹配项,您必须检查数据
以查看它是否包含您想要的内容预计。If this...
...doesn't find any matches (
<colleges>...</colleges>
), then this......will return
undefined
.The first thing you should do is test to see if the
.find()
found anything.If the
alert
gives you0
, then there were no matches, and you'll have to inspect yourdata
to see if it contains what you expect.