jquery基础教程八 load方法及小技巧

From:http://www.cnjquery.com/

首先我们看看手册上的描述

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=" http://www.cnjquery.com/demo/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 />
$(&quot;#btndemo1&quot;).click(function(){<br />
$(&quot;#demo1&quot;).load(&quot;loadhtml.html&quot;); <br />
})</div>
<input type="button" name="Submit" value="加在loadhtml.html 中的ID=div2 的内容" ID='btndemo2'/>
<div ID="demo2" class="redborder"><br />
点击上面按钮将执行:
<br />
<br />
$(&quot;#btndemo1&quot;).click(function(){<br />
$(&quot;#demo1&quot;).load(&quot;loadhtml.html&quot;); <br />
})</div>

loadhtml.html的代码是<br />
<br />
&lt;div ID=&quot;div1&quot;&gt;div1&lt;/div&gt;<br />
&lt;div ID=&quot;div2&quot;&gt;div2&lt;/div&gt;

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值