我正在尝试每5秒轮换一次表格单元格中的文本。但我需要从mysql数据库中获取数据。这是我目前使用的代码,它使用一个html字幕。(代码在php中)。
echo "<marquee behavior=\Slide\" scrollamount=\"3\" direction=\"left\"height=\"100px\">";
echo "<a href=\"".$root."Index.php?page=diary\"><table><tr><td ><h2>--Upcoming Events--</h2></td></tr></table></a>";
echo "<table width=\"50px\"><tr><td></td></tr></table>";
for($count = 0; $count < $num_rows; $count++)
{
$row = mysql_fetch_array($result);
echo "<a href=\"".$root."Index.php?page=diary\"><table class=\"footer-inner\"><tr><td><p2>Event: ".$row['Title']."</p2></td><td width=\"10px\"></td>";
echo "<td><p2>Date: ".$row['Date']."</p2></td></tr>";
echo "<tr> <td><p2>Start Time: ".$row['Start Time']."</p2></td><td width=\"10px\"></td>";
echo "<td rowspan=\"3\"><p2>Details: ".$row['Text']."</p2></td></tr>";
echo "<tr><td><p2>End Time: ".$row['End Time']."</p2></td></tr>";
echo "<tr><td><p2>Location: ".$row['Location']."</p2></td></tr></table></a>";
echo "<table width=\"50px\"><tr><td></td></tr></table>";
}
echo "</marquee>";我已经对此做了一些研究,我发现了如何每隔x秒轮换文本,代码如下:
<html>
<head>
<title>Rotating Text</title>
<script type="text/javascript">
var rotatingTextElement;
var rotatingText = new Array();
var ctr = 0;
function initRotateText() {
rotatingTextElement = document.getElementById("textToChange");
rotatingText[0] = rotatingTextElement.innerHTML; // store the content that's already on the page
rotatingText[1] = "Ten Reason to Buy Gumballs";
rotatingText[2] = "White House bla bla";
setInterval(rotateText, 5000);
}
function rotateText() {
ctr++;
if(ctr >= rotatingText.length) {
ctr = 0;
}
rotatingTextElement.innerHTML = rotatingText[ctr];
}
window.onload = initRotateText;
</script>
</head>
<body>
<span id="textToChange">New Release... Leopard</span>
</body>
</html> 但正如你所看到的,这只做了一行,是的,我可以对表中的每个值都这样做,我对此很满意。但是如何从mysql数据库中获得我想要的内容并将其插入到数组中呢?
我使用php创建页面,我可以使用php获取所有需要的信息,只需将其更改为java脚本格式即可。
--编辑
是否有可能在同一段代码中将php数组转换为javascript数组?
例如:
var rotatingText = Arrayfuction('{php tag} echo $phparray; {php tag}');发布于 2013-04-23 05:36:23
在这里,看看这个:
我认为你的php代码应该类似于:
for($count = 0; $count < $num_rows; $count++)
{
texts.push( ".$row['Text'].");
}https://stackoverflow.com/questions/16156092
复制相似问题