weixin_33688840 2012-10-15 13:09 采纳率: 0%
浏览 38

用jQuery指定div ID

I have buttons and divs and in each part I have them with the same ID I want to get the ID of button and use it for refreshing the div html.how should I write the * section?

   $(function() {
         $(".button").click(function(){ 
         var id=$(this).attr('id');
         var dataString = 'id='+ id ;
        $.ajax({
           type: "POST",
           url: "download_number.php",
           data: dataString,
           cache: false,
           success: function(html)
           {
          *********I HAVE PROBLEM HERE**************
            $('how to get the id of the div from var id of button above?').html(html);
          } 
           });

         });
              });

Div:

  Downloaded:<div id="<?php echo $id; ?>" ><?php echo $downloadcount;?></div>

Button:

 <input type = "button" value="Download" class="button" id="<?php echo $id; ?>" name="dl">

If I get class It will update the whole divs I want to update just the div realted to the button

  • 写回答

9条回答 默认 最新

  • weixin_33719619 2012-10-15 13:11
    关注

    Try something like:

    $('.button').attr('id');
    

    to get the id of the button, then to change it:

    $('.button').attr('id',''); //delete previous id if existing
    $('.button').attr('id','yourNewId'); //set new id
    

    then to use the new id:

    $("#yourNewId").doSomething();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题