如何在HTML上使用jQuery更改div标记中的样式表?或者说有关更改样式表的jQuery代码是什么?
在JavaScript中,我们使用以下代码:
<script type="text/javascript">
function changeStyle() {
document.getElementById('stylesheet').href = 'design4.css';
}
</script>
有没有jQuery的方法?
如何在HTML上使用jQuery更改div标记中的样式表?或者说有关更改样式表的jQuery代码是什么?
在JavaScript中,我们使用以下代码:
<script type="text/javascript">
function changeStyle() {
document.getElementById('stylesheet').href = 'design4.css';
}
</script>
如果要更新整个主题,最好加载一个新的CSS文件。最简单的方法是在服务器端完成,但如果您坚持动态加载:
// Don't know jQuery, this is regular JS:
var newCss = document.createElement('link');
newCss.rel = 'stylesheet';
newCss.type = 'text/css';
newCss.href = '/path/to/new/cssfile.css';
document.body.appendChild(newCss);
document.getElementById('stylesheet').href = 'design4.css';
使用jQuery:
$("#styleshhet").attr('href', 'design4.css');
$(document).on('pagebeforeshow', function () {
var URL = $.mobile.path.parseUrl(window.location).toString().toLowerCase();
if (URL.indexOf("/investment.aspx") > -1 ||
URL.indexOf("/employees.aspx") > -1) {
$("link[href^='../../Public/LongLabels.css']").attr("media", "all");
}
else {
$("link[href^='../../Public/LongLabels.css']").attr("media", "not all");
}
});