dql123000 2017-03-18 22:45
浏览 54

在onclick事件上滑动隐藏的div

I have the following php while loop code:

while (...($...)){
$convid = $row['ID'];

 echo"
<button onclick='getconvo($convid)'>open</button>


    <div class="convowrap"></div>
    ";


    }

and the javascript code

<script type='text/javascript'>
$(document).ready(function(){
$(".convowrap").hide(0)
})
</script>

script type='text/javascript'>
function getconvo(id){
$(".convowrap").hide(0).delay(200).slideDown(500)
var convid = id;
$('.convowrap').load('fetch_info.php', {id : convid}, function () {

       // do something when success
  });
 }
 </script>

When i click on the button above that says 'open,' all of the div that says convowrap slides, but i only want the current div to slide based on the button that was clicked that was generated from the php while loop. If the php loop executed three times, when i click on the first button generated by the first loop, the convowrap div slides on all three entries generated by the loop.

What do I do? Please help?

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • dongyuan7981 2017-03-18 23:00
    关注

    The problem is that all the divs have the same class so its functioning as you it is supposed to ...

    As you have the div after the button you can replace

     $(".convowrap")
    

    With

    $(this).next()
    

    Inside the function for both .load and .hide (Whichever you want)

    more generic

    It may be more usefull to assign another class to each div like

    <div class='convowrap dummyclass$convid'></div>
    

    And on button click change the selector to match that class like

     $('dummyclass'+id)
    

    Hope this helps

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角