jQuery/AJAX - Load content into a div when button clicked?

前端 未结 5 1123
野趣味
野趣味 2021-02-09 04:47

Would someone be able to help here?

I would like to fill a div e.g.

with content from an e

相关标签:
5条回答
  • 2021-02-09 05:10

    Use jQuery.click and jQuery.load:

    $(document).ready(function(){
        $('.classloader.').click(function(){
            $('#contenthere').load('/includes/about-info.html');
        });
    })
    
    0 讨论(0)
  • 2021-02-09 05:20

    Try the following:

    var myurl = 'myfileonthesamedomain.html';
    
    $('button').click(function(){
        $('div.loadme').load(myurl);
    });
    
    0 讨论(0)
  • 2021-02-09 05:25

    Use this simple and sobher it also do run time binding as well:

    $(document).ready(function(){
        $(document).on('click','.classloader',(function(){
            $('#contenthere').load('/includes/about-info.html');
        });
    })
    
    0 讨论(0)
  • 2021-02-09 05:30

    Load latest version of jQuery:

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    

    jQuery code:

    <script language="javascript">
    $(function(){
      $(".classloader").click(function(){
        $("#contenthere").load("/includes/about-info.html");
      });
    });
    </script>
    

    HTML code:

    <p class="classloader">Click Here</p>
    <div id="contenthere"></div>
    
    0 讨论(0)
  • 2021-02-09 05:35

    You could subscribe to the .click() event of the paragraph and then use the .load() function to send an AJAX request to the given url and inject the results into the specified selector:

    $(function() {
        $('.classloader').click(function() {
            $('#contenthere').load('/includes/about-info.html');
            return false;
        });
    });
    
    0 讨论(0)
提交回复
热议问题