div层里能嵌套框架或者新的html页面吗
解答:1,基于Jquery的DIV嵌套htmlhtml代码:
<script src="js/jquery.js"></script>
<div id="btn" > 新页面</div><div id="newDiv"></div>
js代码:$(document).ready(function)(){ $("#btn").click(function(){ $('#newDiv').load('new.html'); });});
点击“新页面”即可实现添加2,基于纯js代码实现嵌套:html代码:<button type="button" id="btn" onClick="javascript:load_home();" > 确认</button>1
js代码:function load_home() { document.getElementById("viewDiv").innerHTML = '<object type="text/html" data="new.html" width="100%" height="100%"></object>'; }
在jquery中,用 $. 和 $().有什么区别,它们的含义分别是什么
$就是jquery对象,$()就是jQuery(),在里面可以传参数,作用就是获取元素如下例子$(".div1") 表示获取类名为div1的元素,例如获取
$(".div1").onclick表示类名为div1的div点击事件jquery中$.,例如$.post(),$.get(),$.ajax()等这些都是jquery这个对象的方法jQuery通用的全局遍历方法$.each()用法实例
1.test.json文件代码:
[
{
"username": "张三",
"content": "沙发."
},
{
"username": "李四",
"content": "板凳."
},
{
"username": "王五",
"content": "地板."
}
]
2.html代码:
<p>
<input type="button" id="send" value="加载"/>
</p >
<div >已有评论:</div>
<div id="resText" ></div>
3.jQuery代码:
<script src="jquery-1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
/*
1.$.each()是jquery的一个通用的遍历方法,可用于遍历对象和数组
2.$.each()函数不同于jquery对象的each()方法,它是一个全局函数,不操作jquery对象,而是以一个数组或者对象作为第一个参数,以一个回调函数作为第二个参数。回调函数拥有两个参数:第一个参数为对象的成员或数组的索引,第二个参数为对应变量或内容
*/
$(function(){
$('#send').click(function() {
$.getJSON('test.json', function(data) {
$('#resText').empty();
var html = '';
$.each( data , function(commentIndex, comment) {
html += '<div ><h6>' + comment['username'] + ':</h6><p >' + comment['content'] + '</p ></div>';
})
$('#resText').html(html);
})
})
})
</script>
还没有评论,来说两句吧...