Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关于响应脚本I'的问题;我在创造_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 关于响应脚本I'的问题;我在创造

Javascript 关于响应脚本I'的问题;我在创造,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正试图为我未来的项目构建一个响应脚本,以便在开发过程中使用和开发,因为我不喜欢自动响应脚本把我的设计搞得一团糟 这个脚本的想法是,它会将您重定向到网站的另一个版本,或者只是加载另一个符合某些常见分辨率的CSS文件 让我先附上我的代码,以便您更好地了解我面临的问题 /*Change CSS and also redirect the page in response to common resolutions.*/ $(document).ready(function() { check

我正试图为我未来的项目构建一个响应脚本,以便在开发过程中使用和开发,因为我不喜欢自动响应脚本把我的设计搞得一团糟

这个脚本的想法是,它会将您重定向到网站的另一个版本,或者只是加载另一个符合某些常见分辨率的CSS文件

让我先附上我的代码,以便您更好地了解我面临的问题

/*Change CSS and also redirect the page in response to common resolutions.*/
$(document).ready(function() {
    checkWidth ();
    $(window).resize(checkWidth);
});
var xFullPath = window.location.pathname;
var xPageName = xFullPath.substring(xFullPath.lastIndexOf("/") + 1);

function checkWidth(){
    var windowWidth = $(window).width(),
        cssLocation = $('link[href$="main.css"]');

    if (windowWidth <= 240){
        cssLocation.attr('href','stylesheets/240-main.css');
        }
    else if (windowWidth <= 490){
        if (xPageName != "smartPhone-index.html"){
            window.location.replace("smartPhone-index.html");
            }
            cssLocation.attr('href','stylesheets/480-main.css');
        }       
    else if (windowWidth <= 768){
        if (xPageName != "index.html"){
            window.location.replace("index.html");
            }
            cssLocation.attr('href','stylesheets/768-main.css');
        }       
    else if (windowWidth <= 1024){
        if (xPageName != "index.html"){
            window.location.replace("index.html");
            }
        cssLocation.attr('href','stylesheets/1024-main.css');
        }       
    else if (windowWidth >= 1280){
        if (xPageName != "index.html"){
            window.location.replace("index.html");
            }
        cssLocation.attr('href','stylesheets/1280-main.css');
        };  
    };
/*更改CSS并根据常见分辨率重定向页面*/
$(文档).ready(函数(){
支票宽度();
$(窗口)。调整大小(选中宽度);
});
var xFullPath=window.location.pathname;
var xPageName=xFullPath.substring(xFullPath.lastIndexOf(“/”)+1);
函数checkWidth(){
var windowWidth=$(window).width(),
cssLocation=$('link[href$=“main.css”]”);

如果(窗口宽度使用Bootstrap),CSS在引导程序中为您处理这个问题。不知道您为什么需要JavaScript,因为它可以很容易地用CSS媒体查询来完成。我将第二个乔治的建议是使用Bootstrap或Buffic之类的东西。GeorgeStocker感谢您的愉快回答,虽然我不是TH的粉丝。基于float dynamics的e,正如我之前所说的,它打乱了我的设计。@APAD1我很感激您的友好回答,尽管旧浏览器不支持CSS媒体查询,我仍然会使用JavaScript将访问者重定向到另一个HTML页面。使用填隙片/多边形填充,您可以获得对媒体查询的支持,一直回到IE7。我刚刚完成了一个网站在IE7/8的基础上工作得很好。