我有一个php循环,输出一个带有表单的框。目前,如果您单击按钮或更改其中一个选择框,则顶层将被隐藏,并显示另一个图层,其上有一个休息按钮。如果'todo'div的文本字符串长于3,我希望它自动隐藏顶层。我尝试使用类似的编程对此进行编程,以便在单击按钮/选项时选择。任何人都可以看到我的编程有什么问题吗?下面是我用于todo的代码。
<script>
$(document).ready(function() {
if ($(".todo").text().length > 3) {
$(this).parentsUntil(".submitted").addClass("hidediv");
$(this).parentsUntil(".submitted").removeClass("showdiv");
}
});
</script>
这是完整的代码
<!DOCTYPE html>
<html>
<head>
<?php include 'dbconnection.php'; ?>
<link href="hidphptest.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".cars").change(function(){
$(this).parentsUntil(".submitted").addClass("hidediv");
$(this).parentsUntil(".submitted").removeClass("showdiv");
});
});
</script>
<script>
$(document).ready(function(){
$(".go45").click(function(){
$(this).siblings().addClass("showdiv");
$(this).siblings().removeClass("hidediv");
});
});
</script>
<script>
$(document).ready(function(){
$(".go1").click(function()
{$(this).parent().addClass("hidediv");
$(this).parent().removeClass("showdiv"); });});
</script>
<script>
$(document).ready(function() {
if ($(".todo").text().length > 3) {
$(this).parentsUntil(".submitted").addClass("hidediv");
$(this).parentsUntil(".submitted").removeClass("showdiv");
}
});
</script>
<body>
</br>
<form method="post" action="testplace2.php">
<select name="classu" >
<option disabled="disabled" selected="selected">Select Class</option>
<?php
$selectclass=$connect->query("SELECT DISTINCT class FROM `firstnametest` ");
while($rows=$selectclass->fetch_array())
{
?>
<option value="<?php echo $rows['class']; ?>"><?php echo $rows['class']; ?>
</option>
<?php
}
?>
<input type="submit" value="Add Group" style="width: 317px; height: 45px"/>
</form>
</select>
<?php
include 'dbconnection.php';
$groupder = $_POST['classu'];
?>
<h1><?php echo $groupder ?></h1></br>
<?php
$query=mysqli_query($connect,"SELECT * from firstnametest where class =
'$groupder'" );
// Initiate a counter variable
$i = 1;
while ($row=mysqli_fetch_array($query))
{
?>
<div class="submitted ">
<button id="butest<?= $i ?>" type="button" class="go45 btn btn-info "
value="<?php echo$row["id"]; ?>">Go Back</button>
<div class="todo "></br><?php echo$row["surname"]; ?></br>
<button type="button" onclick="return buter('<?= $i ?>')" class="go1 btn
btn-info " value="<?php echo$row["id"]; ?>">Button test</button>
<select class="cars" >
<option disabled="disabled" selected="selected">Group </option>
<option value="Group 1">Group 1</option>
<option value="Group 2">Group 2</option>
<option value="Group 3">Group 3</option>
<option value="Group 4">Group 4</option>
</select>
<select onchange="return chka('<?= $i ?>')" id="names<?= $i ?>" class="cars
changetest" >
<option disabled="disabled" selected="selected">Activity</option>
<?php
$classdrop=$connect->query("SELECT * from clubs ");
while($rows=$classdrop->fetch_array())
{
?>
<option class="changetest" value="<?php echo $rows['Club']; ?>"><?php echo
$rows['Club']; ?></option>
<?php
}
?>
</select>
<br/>
<div >
</div>
</div>
</div>
<?php
// Increment the counter
$i++;
}
?>
</body>
提前感谢您的帮助
答案 0 :(得分:0)
问:有人可以看到我的编程有什么问题吗?
答案:
在调试之前,您应该做的第一件事是修复html文档并遵循调用外部脚本的正确准则。我还注意到你正在实现在显示页面内执行sql查询的坏习惯,这实际上是开发人员应该避免的常见错误。
include 'dbconnection.php'
示例:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>