0

这段代码不起作用真是太奇怪了..我只想在加载时隐藏一个div,并在我单击新建按钮时显示它..请告诉我哪里做错了..谢谢!

<?php
include('connect.php');
?>

<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>

 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
 <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.min.js"></script>

 <script>



  $(document).ready(function(){


$('#form2').hide();

  $("#form1").validate({
         debug: false,
   rules: {

    plid:"required",
       },
   messages: {

    plid: "Please select a pack name id..",
    },

    submitHandler: function(form) {

    $.ajax
   ({




type: "POST",
url: "aa.php",
data: $('#form1').serialize(),
cache: false,

success: function(response) {
    $('#result1').html(response); 

        }
        });
        }

  });
  });


  </script>
  <script>
$("#new").click(function(){

    $("#form2").show();
})
  </script>

</head>
<body>

Packing List
</br>
<form id="form1" name="form1" action="" method="post">
<?php   


echo '<select  name="plid" id="plid">';
echo '<option value="" selected="selected">--Select the Pack Name--</option>';
$tempholder = array();
$sql="SELECT CONCAT( p.pl_no,  '_', DATE_FORMAT( p.pl_dt,  '%d/%m/%Y' ) ,  '_', g.acname ) AS plname, p.pl_id FROM packlist p, glmast g WHERE g.gl_id = p.gl_id ORDER BY pl_dt DESC , pl_no DESC LIMIT 30";


$query = mysql_query($sql) or die(mysql_error());
$nr = mysql_num_rows($query);
for ($i=0; $i<$nr; $i++){
$r = mysql_fetch_array($query);
if (!in_array($r['plname'], $tempholder)){
$tempholder[$i] = $r['plname'];
echo "<option value='$r[pl_id]'>".$r["plname"]."</option>";
}
}

echo '</select>';

?><br/>

<input type="submit" name="delete" value="Delete"/><br/>
<input type="submit" name="edit" id="edit" value="Edit"/><br/>

</form>
<form>
<input type="submit" name="new" id="new" class="new" value="New" /><br/>
</form>

<div id="newform" class="newform">

        <form name="form2" class="form2" id="form2" method="post" action="aa.php">
        <P>
            <LABEL for="plidnew">PackList No 
                      <INPUT type="text" id="plidnew" name="plidnew"></LABEL><BR><BR>
            <LABEL for="itemidnew">Item Id 
                      <INPUT type="text" id="itemidnew" name="itemidnew"></LABEL><BR><BR>
            <LABEL for="quannew">Quantity
                      <INPUT type="text" id="quannew" name="quannew"></LABEL><BR><BR>
            <LABEL for="potnew">Potency
                      <INPUT type="text" id="potnew" name="potnew"></LABEL><BR><BR>
            <LABEL for="sizenew">Size
                      <INPUT type="text" id="sizenew" name="sizenew"></LABEL><BR><BR>

            <INPUT type="submit" id="newsubmit" name="newsubmit" value="Submit"> <INPUT type="reset">
            </P> 

        </form>

</div>
<div id="result1"></div>
</body>

</html>

所以我尝试了jquery的各种组合,但是当页面加载时,div被隐藏了..但是当我点击它时没有显示出来..任何帮助!!!

4

1 回答 1

1

你应该把任何代码更具体的代码,不仅仅是复制和粘贴你所有的代码,因为我们不能尝试你的脚本,比如连接到 mysql ......但是

你应该把

$("#new").click(function(){
      $("#form2").show();
});

里面

  $(document).ready(function(){...

并且不要对所有按钮使用 type="submit" ,因为它会启动表单的提交,您应该使用例如:

<input type="button" name="new" id="new" class="new" value="New" />
于 2013-05-11T11:11:56.177 回答