如何使用 google ajax feed api 在我的代码中获取“guid”的nodeValue
这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Feed API - Simple Example</title>
<!--<script type="text/javascript" src="http://www.google.com/jsapi"></script>-->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src='jquery-1.4.2.js'></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://maps.google.com/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=259e&msa=0&output=georss&msid=109685068115364659392.00048b5b630141d82b83a");
feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
feed.load(function(result) {
if (!result.error) {
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var guid=entry.xmlNode.getElementsByTagName("id") || entry.xmlNode.getElementsByTagName("guid") ||0
//console.log($('id',entry.xmlNode.xmlDocument)||$('guid',entry.xmlNode.xmlDocument))
console.log(guid)
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="feed"></div>
</body>
我的代码什么也没有得到,
我使用jquery的方法text()或html(),但也没有,
所以我能做什么。
谢谢
this is my code :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google AJAX Feed API - Simple Example</title>
<!--<script type="text/javascript" src="http://www.google.com/jsapi"></script>-->
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src='jquery-1.4.2.js'></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://maps.google.com/maps/ms?ie=UTF8&hl=zh-CN&vps=1&jsv=259e&msa=0&output=georss&msid=109685068115364659392.00048b5b630141d82b83a");
feed.setResultFormat(google.feeds.Feed.MIXED_FORMAT);
feed.load(function(result) {
if (!result.error) {
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var guid=entry.xmlNode.getElementsByTagName("id") || entry.xmlNode.getElementsByTagName("guid") ||0
//console.log($('id',entry.xmlNode.xmlDocument)||$('guid',entry.xmlNode.xmlDocument))
console.log(guid)
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="feed"></div>
</body>
and my code did not get nothing ,
i use jquery's method text() or html() ,but not too ,
so what can i do .
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
或
但是,你不能这样做:
因为,代码永远不会到达
$(somethingElse)
,因为$(something)
将返回一个 jQuery 对象,即使没有匹配成立。一个对象(甚至是一个空的 jQuery 对象)是 truthy,因此无论$(somethingElse)
的值是什么,表达式都将为 true,JavaScript 会完全跳过对它的求值。这称为短路评估。如果您确实想先通过"id"
查找,然后通过"guid"
查找,那么请尝试:这样做的原因是因为我们试图在每个中获取一个字符串表达式的步骤,而不是对象。空字符串在 JavaScript 中是假的,因此像这样的表达式
将返回第二个表达式 (42) 作为结果。
Try
or
But, you cannot do:
because, the code will never get to
$(somethingElse)
, since$(something)
will return a jQuery object even if no match is found. An object (even an empty jQuery object) is truthy, thus the expression is going to be true no matter what the value of$(somethingElse)
, JavaScript skips evaluating it altogether. It's called short-circuit evaluation. If you do want to find first by"id"
, then by"guid"
, then try:The reason this works is because we are trying to get a string in each step of the expression, and not an object. An empty string is falsy in JavaScript, hence expressions like:
will return the second expression (42) as the result.