[英]jquery .show() .hide() does not work
Hello I am new to javascript and jquery. 您好,我是javascript和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: php代码:
<!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']?>
<a id="link<?php echo $counter ?>" href="manage_categories.php?type=edit&id=<?php echo $category['id'];?>">Edit</a>
<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: js文件:
$(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). alert()函数有效,但是我无法隐藏/显示表单(默认情况下显示)。 The php script just returns a list of categories that I have in the database. php脚本仅返回我在数据库中拥有的类别的列表。
There is a error in your PHP code. 您的PHP代码中有错误。 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. 因为您尚未在$ categories变量中保留mysqli对象。 Fix this 解决这个问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.