-5

我有这个脚本,但这不起作用。

function checkWindowSize() {

if ( $(window).width() < 100 ) {document.write("<link rel='stylesheet' type'text/css' href='style.css'");}
}

$(window).load(checkWindowSize);
$(window).resize(checkWindowSize);
4

2 回答 2

1

不要使用document.write... append tohead代替:

$('head').append('<link rel="stylesheet" type="text/css" href="style.css">');

你也有一些语法错误..

在我看来,您想要实现的最佳方法是CSS 媒体查询。而不是你目前正在尝试的。

于 2013-07-06T05:04:44.030 回答
-1

你可以使用这样的东西

$("<link/>", {
   rel: "stylesheet",
   type: "text/css",
   href: "style.css"
}).appendTo("head");

我希望它会有所帮助。

于 2013-07-06T05:20:54.880 回答