how to add effect 'hide (“slow”)' to div inside a PHP while

最后都变了- 提交于 2019-12-31 06:24:34

问题


I have a form that is repeated several times within a div called "formscontainer" in PHP while, I want to make a form submit with their respective div disappears the effect hide ("slow")

here the example code

<script type="text/javascript">
 $(function() {
      $("form").each(function() {
          $(this).validate( {
              submitHandler: function(formbeingsubmitted) {
                  $.post('process.php', $(formbeingsubmitted).serialize(), function(data) {
                      $('#results').html(data);
                      $ (formbeingsubmitted).hide("slow");
                  });
              }
          });
      });
  });
</script>
</head>
<body>
<?php do { ?>
<div id="formscontainer">
  <form method="post" id="form1">
    <label for="name" id="name_label">form </label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>

    <input type="submit" name="submit" value="SEND"> 
  </form>
</div>
<div id="formscontainer">
  <form method="post" id="form1">
    <label for="name" id="name_label">form </label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>

    <input type="submit" name="submit" value="SEND"> 
  </form>
</div>
<div id="formscontainer">
  <form method="post" id="form1">
    <label for="name" id="name_label">form </label>  
    <input type="text" name="name" id="name" size="30" value=""/>  
    <br>

    <input type="submit" name="submit" value="SEND"> 
  </form>
</div>
<?php } while ($row_var = mysql_fetch_assoc($var)); ?>
<div id="results"></div>
</body>
</html>

回答1:


$(function () {
    $("form").each(function () {
        var par_div = $(this).closest('div'); //finding the closest div
        $(this).validate({
            submitHandler: function (formbeingsubmitted) {
                $.post('process.php', $(formbeingsubmitted).serialize(), function (data) {
                    $('#results').html(data);
                    $(formbeingsubmitted).hide("slow");
                    par_div.hide('slow'); //hide the div
                });
            }
        });
    });
});

you can also use

$(this).parents('div'); instead of $(this).closest('div');

but this $(this).closest('div'); is faster



来源:https://stackoverflow.com/questions/18256359/how-to-add-effect-hide-slow-to-div-inside-a-php-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!