js 中style对象无法获取外链css属性,返回一个空,但为何还能通过style设置外链的css属性呢?

var$=function(){returnnewBase();}functionBase(){this.element=[];}//设置cssBase.prototyp... var $ = function(){
return new Base();
}

function Base(){

this.element=[];
}
//设置css
Base.prototype.css=function(attr,value){
for(var i=0;i<this.element.length;i++){
//获取css属性
if(arguments.length == 1){

if(typeof window.getComputedStyle!='undefined'){
return window.getComputedStyle(this.element[i],null)[attr];
}else if(typeof this.element[i].currentStyle!='undefined'){
return this.element[i].currentStyle[attr];
}
}//设置css属性
this.element[i].style[attr]=value;
}

return this;
}
上面代码可以运行,问题就是style无法获取外链css样式属性,却能修改属性。
展开
 我来答
品流教你做潮男
2016-08-24 · TA获得超过141个赞
知道小有建树答主
回答量:247
采纳率:93%
帮助的人:86.2万
展开全部

JS是不能获取引用的CSS的样式属性的,无论是外链还是内链,修改某个CSS也是通过style这样的方式,比如说

<ul class="channel" style="color: #fff;">

当然上面这样的HTML 你也可以获取到 channel 这个节点的 color的属性,其他的属性就无法获取,但是你却可以修改其他任何的属性。

无名零零7
2016-08-24 · TA获得超过255个赞
知道小有建树答主
回答量:607
采纳率:50%
帮助的人:176万
展开全部
你确定js写对了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式