a.html中有多个标签id=1,id=2等等,我想通过地址a.html?id=1直接显示需要的标
a.html中有多个标签id=1,id=2等等,我想通过地址a.html?id=1直接显示需要的标签需要怎么做啊,或者您告诉我相关的术语也行...
a.html中有多个标签id=1,id=2等等,我想通过地址a.html?id=1直接显示需要的标签需要怎么做啊,或者您告诉我相关的术语也行
展开
1个回答
展开全部
用jquery的一种解决方法:例子如下:
test.html:(注意,这里任何html页面都可以用,我只是在这里面加了个div
<div id='gettag'></div>,用来显示信息。jquery.js可以在jquery上下载到,改下名字就可以,地址:http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.min.js)
<!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=ISO-8859-1" />
<title id='kkk'>jQuery Starterkit</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="custom.js" type="text/javascript"></script>
</head>
<body>
<h1>jQuery Starterkit</h1>
<h2>This page contains code to test the examples. Most of it is only relevant for a example.</h2>
<div id='gettag'></div>
<a id="first" href="#" >Some link</a>
<div class="stuff">
<a name="top" href="#bottom">Go to bottom</a>
<div class="buttons">
<button>First button</button>
<button>Second button</button>
</div>
<ol id="orderedlist">
<li>First element</li>
<li>Second element</li>
<li>Third element</li>
</ol>
<ol id="orderedlist2">
<li>First element, second list</li>
<li>Second element, second list</li>
<li>Third element, second list</li>
<li>Li with child ul
<ul>
<li>Child One</li>
<li>child two</li>
</ul>
</li>
</ol>
<label for='text1'>test</label><input type="text" name='text1'>
<div id="rating">Container</div>
<a id="reset" href="#">Reset!</a>
<form id="form">
Form 1
<input value="XXX" />
<input />
</form>
<form>
Form 2
<input value="YYY" />
<input />
</form>
<form>
Form 3
<input type="checkbox" />
<input type="checkbox" checked="checked" />
</form>
</tbody>
</table>
<a name="bottom" href="#top">Go to top</a>
</div>
</body>
</html>
custom.js
//获取html的tag
$(document).ready(function() {
var arr_tag=Array();
var arr_id=Array();
var arr_class=Array();
var str='';
$('*').each(function(i){
arr_tag[i]=$(this).get(0).tagName;
arr_id[i]=($(this).attr('id')? $(this).attr('id'): 'non');
arr_class[i]=($(this).attr('class')? $(this).attr('class'): 'non');
str +="</br>"+arr_tag[i]+" id='"+arr_id[i]+"' class='"+arr_class[i]+"'";
});
$('#gettag').html(str);
});
test.html:(注意,这里任何html页面都可以用,我只是在这里面加了个div
<div id='gettag'></div>,用来显示信息。jquery.js可以在jquery上下载到,改下名字就可以,地址:http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.min.js)
<!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=ISO-8859-1" />
<title id='kkk'>jQuery Starterkit</title>
<script src="jquery.js" type="text/javascript"></script>
<script src="custom.js" type="text/javascript"></script>
</head>
<body>
<h1>jQuery Starterkit</h1>
<h2>This page contains code to test the examples. Most of it is only relevant for a example.</h2>
<div id='gettag'></div>
<a id="first" href="#" >Some link</a>
<div class="stuff">
<a name="top" href="#bottom">Go to bottom</a>
<div class="buttons">
<button>First button</button>
<button>Second button</button>
</div>
<ol id="orderedlist">
<li>First element</li>
<li>Second element</li>
<li>Third element</li>
</ol>
<ol id="orderedlist2">
<li>First element, second list</li>
<li>Second element, second list</li>
<li>Third element, second list</li>
<li>Li with child ul
<ul>
<li>Child One</li>
<li>child two</li>
</ul>
</li>
</ol>
<label for='text1'>test</label><input type="text" name='text1'>
<div id="rating">Container</div>
<a id="reset" href="#">Reset!</a>
<form id="form">
Form 1
<input value="XXX" />
<input />
</form>
<form>
Form 2
<input value="YYY" />
<input />
</form>
<form>
Form 3
<input type="checkbox" />
<input type="checkbox" checked="checked" />
</form>
</tbody>
</table>
<a name="bottom" href="#top">Go to top</a>
</div>
</body>
</html>
custom.js
//获取html的tag
$(document).ready(function() {
var arr_tag=Array();
var arr_id=Array();
var arr_class=Array();
var str='';
$('*').each(function(i){
arr_tag[i]=$(this).get(0).tagName;
arr_id[i]=($(this).attr('id')? $(this).attr('id'): 'non');
arr_class[i]=($(this).attr('class')? $(this).attr('class'): 'non');
str +="</br>"+arr_tag[i]+" id='"+arr_id[i]+"' class='"+arr_class[i]+"'";
});
$('#gettag').html(str);
});
追问
我不想一次加载出来这个方法行吗?
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询