最近使用一段 jQuery代码实现 循环读取<link>标签实现换肤的代码,页面导入的jQuery版本从1.2换为1.4版本的类库之后debug就报错,查询api后发现是版本问题。
匹配包含给定属性的元素。
下面代码jQuery 1.2 版本有效:
$('link[@rel*=style][@title]').each(
function(i)
{
this.disabled = true;
if ( this.getAttribute('title') == styleName) this.disabled = false;
});
{
this.disabled = true;
if ( this.getAttribute('title') == styleName) this.disabled = false;
});
注意,在jQuery 1.3中,前导的@符号已经被废除!如果想要兼容最新版本,只需要简单去掉@符号即可。
下面代码jQuery 1.3以上 版本有效:
$('link[rel*=style][title]').each(
function(i)
{
this.disabled = true;
if ( this.getAttribute('title') == styleName) this.disabled = false;
});
{
this.disabled = true;
if ( this.getAttribute('title') == styleName) this.disabled = false;
});
上面情况是多个样式文件一并引入模板页;
但是页面因尽量少引入样式文件,下面代码可实现替换样式文件;
$(
"#" + styleId).attr(
"href", stylePath);
转载于:https://blog.51cto.com/forzh/548570