XML 过滤器应用于非 XML 值
我刚刚开始学习js,需要你的帮助。
我有以下代码:
<html>
<head>
<title>test</title>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('.test1').(function(){
this.each(function () {
var a = $(this);
alert(a);
});
});
});
</script>
</head>
<body>
<pre class="test1">
blabla1
blabla2
blabla3
</pre>
</body>
</html>
通过此代码,我想了解“each”如何分割预标记的内容。 Firebug 返回以下错误消息:
XML 过滤器应用于非 XML 值
该错误是由以下命令引起的:
$('.test1').(function(){...
我做错了什么?
非常感谢!
I am just starting to learn js and need your help.
I have following code:
<html>
<head>
<title>test</title>
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('.test1').(function(){
this.each(function () {
var a = $(this);
alert(a);
});
});
});
</script>
</head>
<body>
<pre class="test1">
blabla1
blabla2
blabla3
</pre>
</body>
</html>
With this code I wanted to find out how "each" will split the content of the pre-tag. Firebug returns following error message:
XML filter is applied to non-XML value
The error is caused by this command:
$('.test1').(function(){...
What am I doing wrong?
Many thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您确实想了解
.each
在示例中的工作原理,请将代码更改为:但是,就像 @James_Johnson 之前所说,
.each
函数中的代码只会执行一次,因此您可能会在警报消息中
看到要使
.each
迭代,您必须执行以下操作If you really want to see how
.each
works in your example, change code to:However, like @James_Johnson said earlier, the code in
.each
function will only execute once, so you are likely to seein your alert message
To make
.each
iterate, you have to do sth likeThe only thing inside of the
<pre>
tag is text, so there's no need foreach()
in this case. Try something like this instead:如果你真的想把文字分解,你可以试试这个。
If you really want the text broken down, you can try this.