【发布时间】:2014-12-01 11:46:39
【问题描述】:
我正在使用 php 和 javascript 来展开或折叠一些 div [必须由 deafult 折叠],方法是在 div 上设置一个按钮 [默认情况下应展开其文本],当我单击该按钮时,div 会展开并且该按钮的文本应自动更改为“折叠”,如果我再次单击该折叠按钮,则应关闭 div,默认情况下将文本更改为“展开”,默认情况下所有 div 都应关闭这是我正在使用的下面给出的代码:
<!DOCTYPE html>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
<script type="text/javascript">
function change()
{
if(document.getElementById("myButton1").value=="expand")
{
document.getElementById("myButton1").value="collapse";
$(document).ready(function(){
$("#myButton1").click(function(){
$("div.container").hide("slow");
});
}
else
{
document.getElementById("myButton1").value="expand";
$(document).ready(function(){
$("#myButton1").click(function(){
$("div.container").show("slow");
});
}
}
});
</script>
</head>
<body>
<?php
for($i=0;$i<=3;$i++)
{
echo"<div style='position:relative;border:1px solid #A5BEBE;background-color: #E7EFEF; width:100%; height:300px;'> <input onclick='change()' type='button' value='expand' id='myButton1' style='position:relative;left:85%;top:4%;background- color:#B20000;color:white;width:70px;height:20px;font-size:15px;' >";
echo "<div class='container' style='border:1px solid #A5BEBE;background-color: white;width:100%;height:92.5%;'>
some text here
</div>";
echo "</div><br><br>";
}
?>
</body>
</html>
我只是 php 的初学者,所以尽我所能,但力求得到想要的结果,请提前帮助我解决这个问题
这里有更多信息
它不适用于我的实际代码:
while($runrows = mysql_fetch_assoc($getquery))
{
$title = $runrows ['sometext'];
$desc = $runrows ['sometext'];
$url = $runrows ['sometext'];
$a = $runrows ['sometext'];
$b = $runrows ['sometext'];
$c = $runrows ['sometext'];
$d = $runrows ['sometext'];
$e = $runrows ['sometext'];
$f = $runrows ['sometext'];
$g = $runrows ['sometext'];
echo "
<div style='position:relative;border:1px solid #A5BEBE;background-color: #E7EFEF;width:84%;'> <input onclick='change()' type='button' value='expand' class='myButton' style='position:relative;left:85%;top:4%;background- color:#B20000;color:white;width:70px;height:30px;font-size:15px;' > <b><p style='padding- bottom:2px;font-size:30px;'><font color='red'>".$title."</font></p></b><p><b>sometext :</b>$desc<br>
<b> sometext:-</b><a href='".$url."'>$url</a><br>
<b>sometext :</b>$b<br>
<b>sometext :</b>$c<br>
<b>sometext :</b>$d<br>
<b>sometext :</b>$e<br>
<b>sometext :</b>$f<br>
<b>sometext :</b>$g</p>";
echo "<div class='container' style='border:1px solid #A5BEBE;background-color: white;'>";
include ('botfunction.php');
echo "</div>";
echo "</div><br>";
}
@TheGr8_Nik 您的代码不适用于此。这是实际代码的一小部分,但它在那里不起作用
【问题讨论】:
标签: javascript php