gpt4 book ai didi

javascript - 在空 RSS 提要后显示文本

转载 作者:行者123 更新时间:2023-11-28 01:10:57 27 4
gpt4 key购买 nike

我是 php 新手,希望有人能提供帮助。
我已经能够通过从互联网上提取不同的代码来启动并运行 RSS feed。
我想要实现的是,如果 RSS 提要为空,我希望它显示一条消息“当前没有警告”
如果 RSS 提要中有项目,我希望它显示该项目,以及下面设置为隐藏的 div。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
<title>Weather Warnings for Queensland - Issued by the Bureau of Meteorology</title></head>
<link type="text/css" href="rss-style.css" rel="stylesheet">
</head>
<script type="text/javascript">
window.setInterval (BlinkIt, 500);
var color = "#0000FF";
function BlinkIt () {
var blink = document.getElementById ("blink");
color = (color == "#FA000C")? "#0000FF" : "#FA000C";
blink.style.color = color;
}
</script>

<body bgcolor="#999">
<h1>Weather Warnings for Queensland - Issued by the Bureau of Meteorology</h1>
<hr>

<br>

<!-- display current weather warnings -->

<fieldset class="rsslib">
<?php
require_once("rsslib.php");
$url = "http://www.bom.gov.au/fwo/IDZ00056.warnings_qld.xml";
echo RSS_Display($url, 3, false, true)
//if there is no warning, i would like to display text saying "There are no current warnings"
// if there are warnings, I would like it to display the RSS, and also display the below wrapper blinking text.
?>
</fieldset>


<!---------------------------- echo "There are no current weather warnings" ---------------------------------->


<!-- this is where I put my blinking text, this is not currently set to only display when there is a warning-->

<div id='wrapper' style="display: none">
<div id="blink">
Current Weather Warning!
</div>

<div id="direction">
Please go to www.bom.gov.au for more details.
</div>
</div>

</body>
</html>

任何帮助将不胜感激,如果需要的话我可以复制 rsslib.php ?

最佳答案

当您调用RSS_Display时,不是立即显示它,而是将其返回值存储在变量中。然后您可以测试它是否为空字符串(没有任何内容可显示),并采取相应的操作:

$rss = RSS_Display($url, 3, false, true);
if ($rss == '')
{
// nothing shown, do whatever you want
}
else
{
// something to display
echo $rss;
// you can add other stuff here
}

关于javascript - 在空 RSS 提要后显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24447103/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com