8 load方法及小技巧

it2022-05-09  28

首先我们看看手册上的描述 load(url, params, callback) 装入一个远程HTML内容到一个DOM结点。 注意:避免用装入的scripts脚本,装入脚本改用$.getScript.当任何字符显示时,IE会忽略所有的脚本。 下面我们看看下面的代码 $("#btndemo1").click(function(){    $("#demo1").load("loadhtml.html"); }) 复制代码 当点击 btndemo1按钮时候 将会把loadhtml.html的内容加载到 id=demo1 的div里面 这个很简单大家都容易理解下面我们看看下面的代码 $("#btndemo2").click(function(){    $("#demo2").load("loadhtml.html #div2"); }) 复制代码 当点击 btndemo1按钮时候 将会把loadhtml.html的内容里面 id=div2 元素里面的内容 加载到 id=demo1 的div里面 loadhtml.html #div2注意中间一定要有空格 所有代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>jquery基础教程六(滑动效果函数之slideDown,slideToggle和slideUp)</title><script language="javascript" src="jquery.js"></script><style> .redborder{border:2px dashed #ff0000 }</style><SCRIPT LANGUAGE="JavaScript"><!--$(document).ready(function() { $("#btndemo1").click(function(){    $("#demo1").load("loadhtml.html"); })     $("#btndemo2").click(function(){    $("#demo2").load("loadhtml.html #div2"); })})//--></SCRIPT></head><body> <input type="button" name="Submit" value="加在loadhtml.html" ID='btndemo1'/><div ID="demo1" class="redborder"><br />点击上面按钮将执行:<br /><br />$("#btndemo1").click(function(){<br />$("#demo1").load("loadhtml.html"); <br />})</div><input type="button" name="Submit" value="加在loadhtml.html 中的ID=div2 的内容" ID='btndemo2'/><div ID="demo2" class="redborder"><br />点击上面按钮将执行:<br /><br />$("#btndemo1").click(function(){<br />$("#demo1").load("loadhtml.html"); <br />})</div> loadhtml.html的代码是<br /><br /><div ID="div1">div1</div><br /><div ID="div2">div2</div> </body></html>

转载于:https://www.cnblogs.com/n666/archive/2010/04/01/2190938.html


最新回复(0)