开发者

Generate dynamic hyperlink based on querystring

开发者 https://www.devze.com 2022-12-15 00:41 出处:网络
开发者_运维知识库I wanna generate Hyperlink based on query string .Let me explain it more Topics clicked rite now:(here I want my hyperlinks)....,....
开发者_运维知识库

I wanna generate Hyperlink based on query string .Let me explain it more

Topics clicked rite now:(here I want my hyperlinks)....,....

1.Cat1

2.Cat2

3.Cat3

when i click cat1 it generate querystring: ?Cat=Cat1

when I click on cat2 it will generate querystring ?Cat=Cat2

so based on that I want to create hyperlink whose text is query string(value)

and url is url-(name and value of that query string)lets say for cat1

if currently url is http://www.google.com/?Cat=Cat1&subcat=subcat1 so text should be cat1(and its url should be www.google.com/?subcat=subcat1)


You may want to take a look at the jquery.query plugin. In particular the get function which returns an array of tokens that you can iterate over.

Something like this should get you started:

<html>
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery.query.js"></script>
<script type="text/javascript">

$(document).ready(function() {
    $.each($.query.get(), function(val, prop) {
        $('.menu').append($('<a />').attr('href', $.query.empty().set(val, prop).toString()).text(val));
        $('.menu').append($('<br />'));
    });
});

</script>
</head>
<body>
   <div class="menu">
   </div>
</body>
</html>


i would say that probably the way to go for this is the following (syntax isnt correct most likely)

I believe this is some regular string manipulation..

var cat1 = "topic1";
var cat2 = "topic2";
var subcat1 = "subtopic1"; etc
url = "http://google.com/?cat=" + cat1 + "&subcat=" + subcat1
<a href=url/>CAT 1 Link<a>

i hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消