简体   繁体   中英

Auto Loading HTML in a Div with Javascript

I'm looking to use this code in JS Fiddle http://jsfiddle.net/syE7s/ to load some content into a div.

It's exactly what I need but I want link A to auto load when the page loads. My knowledge of Javascript is fairly minimal so if someone could get it working in jsfiddle I would be very greatful.

I've tried googling everything but I just can't seem to make it work.

It is essential I use the HTML as the links I use parse tokens that use {} to identify them as tokens but it obviously gets confused with Javascript when they are sat together.

enter code here

thanks

Here is a working JS Fiddle, I added a function to load the first link :

function launch() {
    var link = $('#A').attr("href");
    $('#target').load(link);
}

launch();

http://jsfiddle.net/dhmLjme6/

You can add just one line to your javascript.

It will look like this ( line 3 ):

$(document).ready(function(){

  $('#target').load($('.trigger').attr("href"));

  $('.trigger').click(function(e){
      e.preventDefault();
      var link = $(this).attr("href");

      $('#target').load(link);

  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM