ds0678 2017-07-17 22:18
浏览 618

jquery .show()。hide()不起作用

Hello I am new to javascript and jquery. I am trying to show the form when I choose "edit", however I cannot make it work. Any help/advise is appreciated.

php code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Manage Categories</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript" src="test.js"></script>
</head>

<body>

<h1>Manage Categories</h1>
<h3>List of current categories: </h3>
<ul>
<table>

    <?php 
        $counter = 0;
        while($category = $categories->fetch_assoc()){
        if($category['name'] === "+ New Category"){
            continue;
        }
    ?>
        <tr>
            <td>
            <li>
                <?php echo $category['name']?>&nbsp;
                <a id="link<?php echo $counter ?>" href="manage_categories.php?type=edit&id=<?php echo $category['id'];?>">Edit</a>&nbsp;&nbsp; 
                <a href="manage_categories.php?type=delete&id=<?php echo $category['id'];?>">Delete</a>
            </li>
            </td>
        </tr>

<div id="edit_form<?php echo $counter ?>">
    <form action="manage_categories.php?type=edit&id=<?php echo $category['id'];?>" method="POST">

        <tr id="abc">
            <td>New category name:</td>
            <td><input type="text" name="new_cat" /></td>
            <td><input type="submit" name="submit" value="Change" /></td>

        </tr>

    </form>
  </div>
    <?php
    $counter++; 
    }

    ?>

    <form action="manage_categories.php?type=add" method="POST">
        <tr>
            <td><a href="manage_categories.php?type=add">Add New Category</a></td>
        </tr>

        <tr>
            <td>New category name: </td>
            <td><input type="text" name="new_cat" /></td>
            <td><input type="submit" name="submit" value="Add" /></td>
        </tr>
    </form>

</table>
</ul>

<a href="<?php echo $journal_url ?>">Return to journal homepage</a>
</body>
</html>

js file:

$(document).ready(function () {
    $("#edit_form1").hide();
    $("#link1").on("click", function(){
        alert("hello");
        if($("#edit_form1").is(":visible")){
                $("#edit_form1").hide();
            } else {
                $("#edit_form1").show();
            }
    });

    $("#link2").on("click", function(){
        alert("hello");
        $("#edit_form2").hide();
    });


});

The alert() function works but I just cannot hide/show the form (it is shown by default). The php script just returns a list of categories that I have in the database.

  • 写回答

1条回答 默认 最新

  • douzhan8395 2017-07-17 22:31
    关注

    There is a error in your PHP code. At first fix that bug . you have used

    while($category = $categories->fetch_assoc());
    Here
    $categories
    is undefinded. Because you have not kept object of mysqli in $categories variable. Fix this
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog