我有这个脚本,但这不起作用。
function checkWindowSize() {
if ( $(window).width() < 100 ) {document.write("<link rel='stylesheet' type'text/css' href='style.css'");}
}
$(window).load(checkWindowSize);
$(window).resize(checkWindowSize);
我有这个脚本,但这不起作用。
function checkWindowSize() {
if ( $(window).width() < 100 ) {document.write("<link rel='stylesheet' type'text/css' href='style.css'");}
}
$(window).load(checkWindowSize);
$(window).resize(checkWindowSize);
不要使用document.write
... append tohead
代替:
$('head').append('<link rel="stylesheet" type="text/css" href="style.css">');
你也有一些语法错误..
在我看来,您想要实现的最佳方法是CSS 媒体查询。而不是你目前正在尝试的。
你可以使用这样的东西
$("<link/>", {
rel: "stylesheet",
type: "text/css",
href: "style.css"
}).appendTo("head");
我希望它会有所帮助。