博客
关于我
指定元素样式
阅读量:753 次
发布时间:2019-03-23

本文共 496 字,大约阅读时间需要 1 分钟。

function getStyle(obj, name) {    if (window.getComputedStyle) {        return getComputedStyle(obj, null)[name];    } else {        return obj.currentStyle[name];    }}

这段代码定义了一个用于获取指定元素当前样式的函数。函数接收两个参数:obj表示要获取样式的元素,name表示要获取的样式名称。

函数逻辑如下:

  • 检查浏览器是否支持getComputedStyle方法
  • 如果支持,则使用getComputedStyle方法获取元素的样式集合,然后根据name参数返回对应的样式属性值
  • 如果不支持getComputedStyle方法(如IE8),则使用obj.currentStyle属性来获取元素的样式,同样根据name参数返回对应的样式属性值
  • 这种方法确保了函数在不同浏览器和版本下的兼容性。

    Keiya HTML代码中的段落和标签结构已经被优化,去除了不必要的无效内容。文章结构清晰,内容简洁,适合技术人员阅读和参考。

    转载地址:http://cvszk.baihongyu.com/

    你可能感兴趣的文章
    Python: Windows下用 multiprocessing 的深坑
    查看>>
    python:Could not find platform independent libraries <prefix>解决方法
    查看>>
    Python:datetime tzinfo 时区名称文档
    查看>>
    Python:deepcopy(list) vs new_list = old_list[:]
    查看>>
    Python:Google API - 从消息中获取 mimeTypes
    查看>>
    Python:Google API - 从消息中获取 mimeTypes
    查看>>
    Python:subprocess.call,stdout to file,stderr to file,在屏幕上实时显示stderr
    查看>>
    Python:TypeError:无法连接“str“和“int“对象
    查看>>
    Python:XPath 在 ElementTree 中不可用
    查看>>
    Python:从 FTP 服务器下载文件
    查看>>
    python:从列表中创建元组列表
    查看>>
    Python:从嵌套列表中删除重复项
    查看>>
    Python:从间隔映射到值
    查看>>
    Python:使用 shell=False 的子进程调用不起作用
    查看>>
    Python:修改 PATH 环境变量的平台无关方式
    查看>>
    Python:假与 0
    查看>>
    Python:函数使用
    查看>>
    Python:函数进阶
    查看>>
    Python:在整数的二进制表示中查找最长的二进制间隙
    查看>>
    Python:如何从二进制转换为 base 64 并返回?
    查看>>