选择选项只是链接

时间:2013-04-18 20:49:21

标签: php jquery html select hyperlink

我已经获得了以下脚本,让用户选择"文件夹"然后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>

Selectfolders.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
}
}


?>

1 个答案:

答案 0 :(得分:0)

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

<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' />";