你可以在设置 href 的时候在后面添加一个 query string,例如当前时间,等于是强制更新
$.post('ajax/1.php',function(data) {
var now = new Date().getTime()
$("link[href='css/1.css']").attr('href','css/1.css?' + now)
})
根据class查找到jquery结果后,取索引为0的节点进行修改。
举例:
1、定义2个节点,class名字相同
<div class='t'>122</div><div class='t'>45a</div>
2、查找节点
var divs = $('.t')//根据class名称查找到上面2个节点3、取索引0的节点更新css
divs[0].css("color","red")//第一个节点(122)修改成颜色为红色改变link标签的链接源就可以了,我以前写过的一个类似的,根据喜好选择不同的主题:
页面中引入了这样一个外部样式:
<link id="theme" href="themes/all-hallows-eve.css" rel="stylesheet" type="text/css">请选择主题:
<select id="sel1_tianlidong" onchange="changecss(this)"return false">
<option value="tricolore">tricolore主题</option>
<option value="twilight">twilight主题</option>
<option value="zenburnesque">zenburnesque主题</option>
</select>
脚本代码这样写:
<script>function changecss(obj)
{
document.getElementById("theme").href ="themes/"+obj.value+".css"
return false
}
</script>