doujiao7520 2014-10-06 20:24
浏览 54
已采纳

使用jQuery onClick按钮淡入PHP脚本

I have a PHP script labeled first_page.php. On that page, I currently have a div that looks like this:

<div id="status">
  <h3>To view a list of all rooms statuses, select the link below.</h3>
  <a href="response_data.php" class="button">Show Status</a>
</div>

And links to the correct page, response_data.php. What i'd really like to have instead, is a button that is on the first_page.php, and when that button is clicked, have it load the response_data.php page with .fadeIn().

I've tried to get this jQuery script working, with no luck. Here is what I have tried. I've changed my html to look like this:

<button id="button">Click here to show data</button>
  <div id="data" style="display: none;"> 
<?php include 'response_data.php' ?>
</div>


$('#button').click(function() {
  $('#data').fadeIn(1000);
});

Above, I have added a button and a div that I wanted to fadeIn. The div holds the php script, so I wanted the div to fade the php script in. I set the data CSS to display none. When I click the button, nothing happens. It actually works, but the div data fade's in without having had the button clicked. Then the button remains. I'd like it to not auto click, and also somehow hide the button after the first click.

  • 写回答

1条回答 默认 最新

  • douwan2664 2014-10-06 20:40
    关注

    The jQuery part is just fine. I highly suggest to check that your div#data actually has some text in it.

    To do so, you can try something like:

    console.log($('#data').text().length > 0 ? 'Text found' : 'Could not find text');
    

    Also, to hide the button after it was clicked simply use the hide() method:

    $('#button').on('click', function() {
    
        $('#data').fadeIn(1000);
        $(this).hide();
    
    });
    

    Note: You can also use the fadeOut() method or the remove() method if you wish to remove the button from the DOM.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?