我的html页面有3个按钮,点击事件显示各自隐藏的div格式。按钮的html为:
<button id="edituser" type="submit" onclick="toggle_visibility('c');" style="border:0;width:100px;margin-left: 74px;">
<img src="images/edituser.png" alt="">
</button><br><br>
<button id="companyprofile" type="submit" onclick="toggle_visibility('d');" style="border:0;width:100px;margin-left: 74px;">
<img src="images/companyprofile.png" alt="">
</button><br><br>
<button id="checkticket" type="submit" onclick="toggle_visibility('e');" style="border:0;width:100px;margin-left: 74px;">
<img src="images/checkticket.png" alt="">
</button><br><br>
这些按钮的js代码是:
function toggle_visibility(id) {
var e = document.getElementById(id);
if(document.getElementById("c").id == id)
{
e.style.display = 'block';
document.getElementById("a").style.display='none';
document.getElementById("b").style.display='none';
document.getElementById("g").style.display='none';
document.getElementById("d").style.display='none';
document.getElementById("e").style.display='none';
document.getElementById("f").style.display='none';
document.getElementById("edituser").style.backgroundImage="url('images/edit_user_hover.png')";
}
if(document.getElementById("d").id == id)
{
e.style.display = 'block';
document.getElementById("a").style.display='none';
document.getElementById("b").style.display='none';
document.getElementById("c").style.display='none';
document.getElementById("g").style.display='none';
document.getElementById("e").style.display='none';
document.getElementById("f").style.display='none';
document.getElementById("companyprofile").style.backgroundImage="url('images/edit_company_hover.png')";
}
if(document.getElementById("e").id == id)
{
e.style.display = 'block';
document.getElementById("a").style.display='none';
document.getElementById("b").style.display='none';
document.getElementById("c").style.display='none';
document.getElementById("g").style.display='none';
document.getElementById("d").style.display='none';
document.getElementById("f").style.display='none';
document.getElementById("checkticket").style.backgroundImage="url('images/Check_ticket_hover.png')";
}
div的html如下:
<div class="col-lg-6" style="display:none" id="c" >
<form action="" method="post" name="Country_Filter" id="Country_Filter" >
<select name="id" id="id" class="span2" style="width:150px;" onchange="disp_div()" onchange="this.form.submit();" >
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "v";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$age = array();
$sql = "SELECT * FROM `tbl_user` ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
?>
<option value="">-select user-</option>
<?php if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$age[] = $row;
}
?>
<?php foreach($age as $key=>$row) {
echo "<option value='" . $row['id'] . "' " . (($_REQUEST['id'] == $row['id']) ? "selected": "") . ">" . $row["id"] . "</option>";
?>
<?php }
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
header('Location: webservices.php');
}
mysqli_close($conn);
?>
</select>
<form id="aa" action="" method="GET" >
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "v";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$age = array();
if(isset($_REQUEST['id'])){
$sql = "SELECT first_name ,last_name, phone, company_id, register_on FROM `tbl_user` where id=".$_REQUEST['id'] ." ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$age[] = $row;
?>
<br><br>
<br>
<input type="text" id="first_name" value="<?php echo $row["first_name"]; ?>" name="first_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="First Name*">
<br>
<br><br><br>
<input type="text" id="last_name" value="<?php echo $row["last_name"]; ?>" name="last_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Last Name*">
<br><br><br><br>
<input type="text" id="phone" value="<?php echo $row["phone"]; ?>" name="phone" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Phone*">
<br><br><br><br>
<input type="text" id="company_id" value="<?php echo $row["company_id"]; ?>" name="company_id" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Company ID*">
<br><br><br><br>
<input type="text" id="register_on" value="<?php echo $row["register_on"]; ?>" name="register_on" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Register On*">
<br><br><br><br>
<button name="edituser" id="edituser" type="submit" style="border:0;width:100px;margin-left: 45px;" >
<img src="images/save.png" alt="">
</button>
<button type="submit" style="border:0;width:100px;margin-left: 75px;">
<img src="images/cancel.png" alt="">
</button>
<?php
}
}
}
mysqli_close($conn);
?>
</form>
</div>
<div class="col-lg-6" style="display:none" id="d" >
<form action="" id="abc" method="post" >
<select name="id" id="id" class="span2" style="width:150px;" onchange="this.form.submit();">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "v";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$age = array();
$sql = "SELECT * FROM `tbl_companies` ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
?>
<option value="">-select company-</option>
<?php if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$age[] = $row;
}
?>
<?php foreach($age as $key=>$row) {
echo "<option value='" . $row['id'] . "' " . (($_REQUEST['id'] == $row['id']) ? "selected": "") . ">" . $row["id"] . "</option>";
?>
<?php }
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
header('Location: webservices.php');
}
mysqli_close($conn);
?>
</select>
<br><br>
<br>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "v";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$age = array();
if(isset($_REQUEST['id'])){
$sql = "SELECT company_name ,acess_code ,register_on FROM `tbl_companies` where id=".$_REQUEST['id'] ." ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$age[] = $row;
?>
<br><br><br>
<input type="text" id="company_name" value="<?php echo isset($row["company_name"])?$row["company_name"]:''; ?>" name="company_name" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Company Name*">
<br>
<br><br><br>
<input type="text" id="acess_code" value="<?php echo isset($row["acess_code"])?$row["acess_code"]:''; ?>" name="acess_code" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Acess Code*">
<br><br><br><br>
<input type="text" id="register_on" value="<?php echo isset($row["register_on"])?$row["register_on"]:''; ?>" name="register_on" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Register On*">
<br><br><br><br>
<button name="editcompany" id="editcompany" type="submit" style="border:0;width:100px;margin-left: 45px;" >
<img src="images/save.png" alt="">
</button>
<button type="submit" style="border:0;width:100px;margin-left: 75px;">
<img src="images/cancel.png" alt="">
</button>
<?php
}
}
}
mysqli_close($conn);
?>
</form>
</div>
<div class="col-lg-6" style="display:none" id="e" >
<form action="" method="post" name="Country_Filter" id="Country_Filter" >
<select name="id" id="id" class="span2" style="width:150px;" onchange="this.form.submit();">
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "v";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$age = array();
$sql = "SELECT * FROM `tbl_tickets` ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
?>
<option value="">-select tickets-</option>
<?php if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$age[] = $row;
}
?>
<?php foreach($age as $key=>$row) {
echo "<option value='" . $row['id'] . "' " . (($_REQUEST['id'] == $row['id']) ? "selected": "") . ">" . $row["id"] . "</option>";
?>
<?php }
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
header('Location: webservices.php');
}
mysqli_close($conn);
?>
</select>
</form>
<form action="" method="post" id="e" >
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "v";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$age = array();
if(isset($_REQUEST['id'])){
$sql = "SELECT ticket_no ,user_id ,ticket_status ,register_on FROM `tbl_tickets` where id=".$_REQUEST['id'] ." ";
$result = mysqli_query($conn, $sql);
// echo "User name=" . $row["name"]. "<br>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$age[] = $row;
?>
<br><br><br>
<input type="text" name="FirstName" value="<?php echo $row["ticket_no"] ;?>" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Ticket Owner Name*" readonly>
<br>
<br><br><br>
<input type="text" name="LastName" value="<?php echo $row["user_id"]; ?>" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Registration Date*" readonly>
<br><br><br><br>
<input type="text" name="LastName" value="<?php echo $row["ticket_status"]; ?>" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Expire Date*" readonly>
<br><br><br><br>
<input type="text" name="LastName" value="<?php echo $row["register_on"]; ?>" style="width: 460px;height: 50px;overflow: hidden;" placeholder="Expire Time Status*" readonly>
<br><br><br><br>
<button name="chkticketstatus" id="chkticketstatus" type="submit" style="border:0;width:100px;margin-left: 45px;">
<img src="images/save.png" alt="">
</button>
<button type="submit" style="border:0;width:100px;margin-left: 75px;">
<img src="images/cancel.png" alt="">
</button>
<?php
}
}
}
mysqli_close($conn);
?>
</form>
</div>
在上面给出的每个html表单中,我都有组合框:
<select name="id" id="id" class="span2" style="width:150px;" onchange="disp_div()" onchange="this.form.submit();" >
当用户从组合框中选择一个特定的值时,html表单被提交(onchange =“this.form.submit();”)页面被提交并从数据库中加载相应的值。我面临的问题组合框提交值它加载初始div格式。如何在提交值时使组合框只显示各自的html形式的div?
答案 0 :(得分:0)
在JQUERY中处理表单提交,而不是点击提交。在每个div内部提交一个公共类名称和不同的id,根据它们所属的div。根据它们所属的div,在div唯一id中给出每个表单。之后你可以试试这个:
还将隐藏的输入元素定义为
$(".submitClass").click(function(){
var id=$(this).attr("id");
if(id=="div1") // Need to Submit form1
{
$("#CurrentActDiv").val("1");
$("#form1").submit();
}
else if(id=="div2") // Need to Submit form2
{
$("#CurrentActDiv").val("2");
$("#form2").submit();
}
else if(id=="div3") // Need to Submit form3
{
$("#CurrentActDiv").val("3");
$("#form3").submit();
}
});
这样您就可以知道在服务器端提交了哪种表单 你可以使用if else来读取特定的组合框
String current=request.getParameter("CurrentActDiv");
if(current.equals("1"))
{
read from comobox1
}
else if(current.equals("2"))
{
read from comobox2
}
else if(current.equals("3"))
{
read from comobox3
}