0

我有下面的脚本,让用户选择一个“文件夹”,然后 jquery 代码监听并显示代码。现在代码在一个选择框中,但我希望它们只显示为链接。这可能吗?

这是jQuery:

    <script type="text/javascript">
$(document).ready(function () {
    $("#theselect").change(function() {
var option = $(this).val();
var selectedUser = $("#thename").val();
$.get("selectfolders.php", {select:option,username:selectedUser},function(data){
    $("#theresult").html(data).hide().fadeIn(1000);
});
});
});
</script>



这是查找和显示所有用户文件夹的 php 代码:(这是我想要的链接而不是选择框。)

<select name="theselect" id="theselect">
<option value="">Select</option>
<?
$thelistquery = mysql_query("SELECT * FROM folders WHERE username='$username'");
while ($lrows = mysql_fetch_array($thelistquery)) {
$id = $lrows['ID'];
$foldername = $lrows['foldername'];
$newfoldername = mysql_real_escape_string($foldername);

echo "<option value='$newfoldername'>$newfoldername</option>";
}
?>
</select>

选择文件夹.php

$username = $_GET['username'];
$theselect = $_GET['select'];

$thelistquery = mysql_query("SELECT * FROM folders WHERE username='$username'");
while ($lrows = mysql_fetch_array($thelistquery)) {
$id = $lrows['ID'];
$foldername = $lrows['foldername'];
$newfoldername = mysql_real_escape_string($foldername);

if($_GET['select'] == "$newfoldername") {
//What to display
}
}


?>
4

1 回答 1

0

更改 jQuery 以处理标签单击事件而不是更改事件。请注意,“.folders”选择器是我添加到标签中的类,因此您无需使用引用页面上所有标签的选择器。

<script type="text/javascript">
$(document).ready(function () {
 $(".folders").click(function() {    //<-------Changes here
 var option = $(this).val();
 var selectedUser = $("#thename").val();
 $.get("selectfolders.php", {select:option,username:selectedUser},function(data){
  $("#theresult").html(data).hide().fadeIn(1000);
  });
 });
});
</script>

通过删除周围的标签并将标签更改为标签,修改了输出以显示链接。还添加了一个类以使用 jQuery 轻松选择它。

$thelistquery = mysql_query("SELECT * FROM folders WHERE username='$username'");
while ($lrows = mysql_fetch_array($thelistquery)) {
 $id = $lrows['ID'];
 $foldername = $lrows['foldername'];
 $newfoldername = mysql_real_escape_string($foldername);

 //Changed the below to a link with a class
 echo "<a class='folders' value='$newfoldername'>$newfoldername</a>";
}
echo "<input type='text' value='$username' name='thename' />";
于 2013-04-18T21:15:37.677 回答