我有MySQL数据库结果。
我想显示3行,然后隐藏休息。
当用户点击加载更多数据,然后显示所有行。
问题是当我点击显示更多时,再出现一行。
function myFunction() {
var x_filter1_1 = document.getElementById("myDIV_Filter1_1");
var x_filter1_2 = document.getElementById("myDIV_Filter1_2");
var x_filter1_3 = document.getElementById("myDIV_Filter1_3");
if (x_filter1_1.style.display === "none") {
x_filter1_1.style.display = "block";
x_filter1_2.style.display = "none";
x_filter1_3.style.display = "block";
} else {
x_filter1_1.style.display = "none";
x_filter1_2.style.display = "block";
x_filter1_3.style.display = "none";
}
}
的JavaScript
netsh int ip reset
答案 0 :(得分:0)
您的代码有一些错误:
1)尽量不要像现在这样在代码行中使用 return 的方式:
<a href="#" onclick="myFunction();return false;">show more...</a>
您可以更好地使用它,就像它解释here
一样2)您拥有显示无中代码示例的所有div,用户永远不会看到这些div中的信息,因为您没有任何代码可以开始显示某些他们。在同一行中你放了一个&#34 ;;&#34;风格之后,但必须在风格内。这一行有一个错误:
<div id="myDIV_Filter1_3" style="display:none";>
一定是这样:
<div id="myDIV_Filter1_3" style="display:none;">
&#34; show-hide&#34;您的 javascript 函数上的逻辑myFunction有错误,因为您的div id =&#34; myDIV_Filter1_1&#34; 包含您的代码示例中的另外2个div所以你无法隐藏这个特殊的div ,因为你将失去&#34; show&#34;或者&#34;隐藏&#34;其他2个div。这样,它就不会向您显示您想要看到的其他3行。我修复了所有错误,您可以在此处检查我的代码段中的代码:
function myFunction() {
var x_filter1_1 = document.getElementById("myDIV_Filter1_1");
var x_filter1_2 = document.getElementById("myDIV_Filter1_2");
var x_filter1_3 = document.getElementById("myDIV_Filter1_3");
if (x_filter1_3.style.display === "none") {
x_filter1_1.style.display = "block";
x_filter1_2.style.display = "none";
x_filter1_3.style.display = "block";
} else {
x_filter1_1.style.display = "block";
x_filter1_2.style.display = "block";
x_filter1_3.style.display = "none";
}
}
&#13;
<?php
$query_brands = mysql_query("SELECT distinct pd_filter1 from tbl_brands2 WHERE pd_code in (select pd_code from tbl_product where cat_id='2')") or die(mysql_error());
$count_brands = mysql_num_rows($query_brands);
if($count_brands > 0) {
while($fetch_brands = mysql_fetch_array($query_brands)) {
$record_brands[] = $fetch_brands;
}
}
$i_brands=0;
foreach($record_brands as $records_brands) {
?>
<table border="1" width="215" style="border-collapse: collapse; border-spacing: 0;" bgcolor="#eeeff0">
<tr>
<td>
<?php
$i_brands = $i_brands + 1;
if ($i_brands > 3)
{
?>
<div id="myDIV_Filter1_1">
<?php
}
}
?>
<div id="myDIV_Filter1_2" >
<span class="class22">
<a href="#" onclick="myFunction();">show more...</a>
</span>
</div>
<div id="myDIV_Filter1_3" style="display:none">
<span class="class22">
<a href="#" onclick="myFunction();">show less...</a>
</span>
</div>
</td>
</tr>
</table>
&#13;
希望它有所帮助!