如何使用jQuery基于querystring更改CSS属性值 [英] How to change CSS attribute value based on querystring using jQuery

查看:111
本文介绍了如何使用jQuery基于querystring更改CSS属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的jQuery&我试图自己解决这个问题,没有任何运气。

I am new to jQuery & I tried to resolve this on my own without any luck.

我需要改变基于使用jQuery QueryString的CSS中的值。我尝试了几个无效的脚本。

I need to change the the Value in the CSS based on a QueryString using jQuery. I tried couple of scripts which didn't work.

URL示例: http:www.xyz.com/Page.aspx?pageID = 101& ;语言=阿拉伯语

根据URL中指定的语言,我必须更改显示页面之前,在类 .Image4x4 verticleBar 中右键

Based on the language specified in the URL I have to change the CSS value of float:right in class .Image4x4 and verticleBar before page is displayed.

 .Image4x4
    {
        width:670px;
        float:left; /* for arabic keep right */
        height:550px;
        background-color:Orange; 
    }
    .verticleBar
    {
        width:220px;
        float:left; /* for arabic keep right */
        height:550px;
        background-color:Red;
    }

我试过几个脚本,但是没有按计划工作。

I tried few scripts but it didn't work as planed.

我非常感谢您的帮助。

推荐答案

var queryValues = {};

$.each(window.location.href.split('?').pop().split('&'), function (i, v)
{
    var v = v.split('=');
    if(v.length > 1) // prevent v[1] from erroring if no querystring present
      queryValues[ v[0].toLowerCase() ] = v[1].toLowerCase();
});

if ( queryValues.language == 'arabic' )
{
    $('.Image4x4, .verticleBar').css('float', 'right');
}

如果您不确定将总是有一个查询字符串,应该添加代码来检查。

If you're not sure there'll always be a query string, you should add code to check for that.

这篇关于如何使用jQuery基于querystring更改CSS属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆