开发者

How to load the contents of a static HTML file into a DIV using jQuery?

开发者 https://www.devze.com 2023-02-01 09:37 出处:网络
I have a bunch of static HTML files containing textual data: /a.html /b.html /c.html and a select/dropdown box (#loadExternal) on my main page.

I have a bunch of static HTML files containing textual data:

/a.html
/b.html
/c.html

and a select/dropdown box (#loadExternal) on my main page.

Using jQuery, how can I use the onChange event of the select/dropdown to trigger the appropriate external page to be loaded into my container DIV?

<html>

<select id="loadExternal">
    <option id="a" value="a" selected="selected">Load a.开发者_如何学Gohtml</option>
    <option id="b" value="b">Load b.html</option>
    <option id="c" value="c">Load c.html</option>
</select>

<div id="container">
</div>

</html>


$("#loadExternal").change( function () {
   page = $(this).val();
   $("#container").load(page + ".html")
});


You can bind the change event to the select box. Get the value of the current selection. Use the .load() event to load the page.

$("#loadExternal").change(function(){
    var pageToLoad = this.value + ".html";
    $("#container").load(pageToLoad);
});

See a working demo

0

精彩评论

暂无评论...
验证码 换一张
取 消