gpt4 book ai didi

php - 如何在循环中使用 jQuery UI Accordion

转载 作者:可可西里 更新时间:2023-11-01 08:06:20 31 4
gpt4 key购买 nike

这是 jquery Accordion 效果代码:

 $(function() {
$( "#accordion" ).accordion({
header: "h3"
});
});

这是循环(不确定循环)的数据库(mysql)的输出:

 while($showE = mysqli_fetch_array($show))
{

echo $showE['un_name']; /* this should be accordion head */
echo $showE['un_name_dec']; /* this should be accordion description */
}

所以我的问题是,如何以 Accordion 效果显示它们,一切正常(我可以从数据库中获取记录),但 Accordion 效果没有形成,( Accordion 效果不起作用)以及如何用循环显示它们?

最佳答案

所以,你有两个文件:index.html 和 load_entries.php

index.html:

<html>
<head>
<!-- Make the imports of your stylesheets and scripts here -->
<script type="text/javascript">
$(function() {
$("#accordion").accordion({header: "h3"});
});
function load_entries() {
$.ajax({
url: "load_entries.php",
complete: function(data) {
$("#accordion").html(data.responseText);
}
});
}
</script>
</head>
<body>
<button onclick="load_entries();">Load</button> <!-- Button to load the entries -->
<div id="accordion">

</div>
</body>
</html>

load_entries.php:

<?php
//connect to your database here
$sql = "SELECT * FROM entries"; //replace entries by your own table name
$result = mysqli_query($sql);
while($row = mysqli_fetch_array($result)) {
echo '<h3>'.$row['un_name'].'</h3>';
echo '<div>'.$row['un_name_dec'].'</div>';
}
?>

关于php - 如何在循环中使用 jQuery UI Accordion ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15999309/

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