我有一个多级列表。 只有列表的第一级可见。 现在我想点击列表中的元素,子项目将会出现。
js怎么可能?
<!DOCTYPE html>
<html>
<body>
<h2>A Nested List</h2>
<div id="mylist">
<ul>
<li>Coffee</li>
<li>Tea
<ul>
<li>Black tea</li>
<li>Green tea</li>
</ul>
</li>
<li>Milk</li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:0)
是的,你可以:
<?php
session_start();
$_SESSION['message'] = '';
require_once "../db/connect.php";
if ($_POST['password'] == $_POST['confirmpassword']) {
$username = mysqli_real_escape_string($_POST['username']);
$email = mysqli_real_escape_string($_POST['email']);
$password = md5($_POST['password']);
$query = "INSERT INTO finalx VALUES ('$username' '$password' '$email')";
if (mysqli_query($query) == true) {
$_SESSION['message'] = 'Inregistrare reusita';
header("Location: welcome.php");
}
else {}
}
?>
// JavaScript
jQuery( "li:has(ul)" ).click(function(){ // When a li that has a ul is clicked ...
jQuery(this).toggleClass('active'); // then toggle (add/remove) the class 'active' on it.
});
/* CSS */
ul li ul {
display: none; /* Hide the nested list first */
}
ul li.active ul {
display: block; /* Show the list when class 'active' is added to the li */
color: red;
}