a.html中有多个标签id=1,id=2等等,我想通过地址a.html?id=1直接显示需要的标

2025-02-23 18:19:03
推荐回答(1个)
回答1:

用jquery的一种解决方法:例子如下:
test.html:(注意,这里任何html页面都可以用,我只是在这里面加了个div

,用来显示信息。jquery.js可以在jquery上下载到,改下名字就可以,地址:http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.2.min.js)




jQuery Starterkit





jQuery Starterkit


This page contains code to test the examples. Most of it is only relevant for a example.



Some link


Go to bottom







  1. First element

  2. Second element

  3. Third element




  1. First element, second list

  2. Second element, second list

  3. Third element, second list

  4. Li with child ul

    • Child One

    • child two





Container


Reset!


Form 1





Form 2





Form 3






Go to top





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 +="
"+arr_tag[i]+" id='"+arr_id[i]+"' class='"+arr_class[i]+"'";
});
$('#gettag').html(str);
});