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
精彩评论