radio-button onchange超链接到当前url + querystring

时间:2013-06-25 13:31:03

标签: jquery hyperlink radio-button onchange

我是javascript和jquery的新手。我的网站有jquery运行。

它想要使用单选按钮更改css-link

它有以下单选按钮:

<input type="radio" name="css" value="basic" checked>basic
<input type="radio" name="css" value="round" >round
<input type="radio" name="css" value="zoom" >zoom

我需要的是,当用户更改单选按钮时,脚本应获取当前网址(例如http://mysite.com/about.php)并将所选按钮值添加为查询字符串(例如http://mysite.com/about.php?css=round)和使用query-string重定向到该链接。 (如果当前链接有?css = basic,则应将其更改为?css = round ...)

感谢

2 个答案:

答案 0 :(得分:0)

 $("input:radio").each(function(){
        $(this).click(function(){
            window.location.href = "http://mysite.com/about.php" + "?css=" + $(this).val();
        });
    });

答案 1 :(得分:0)

快速谷歌搜索可以获得答案!

this用于将您的函数绑定到事件

this用于重定向

this是获取当前网址

this用于获取没有查询字符串的网址

this有助于弄清楚如何使用reg exp