V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Cheez
V2EX  ›  Python

怎么样才能设置 dom 的属性 role?

  •  
  •   Cheez · 2018-08-25 13:49:35 +08:00 · 1533 次点击
    这是一个创建于 2064 天前的主题,其中的信息可能已经有所发展或是发生改变。

    var but=document.createElement('button') but.className='Select-option' but.id='show-image-only' but.innerText='ABC' but.tabindex='-1' but.setAttribute('role','option') this.append(but)

    但是最后 button 元素却没有 role 这个属性,可能是因为他这个时候还没有父母

    2 条回复    2018-08-25 22:48:38 +08:00
    l0ng
        1
    l0ng  
       2018-08-25 22:46:11 +08:00 via Android
    如果是你说的原因,那就最后两句顺序换一下咯
    Cheez
        2
    Cheez  
    OP
       2018-08-25 22:48:38 +08:00
    @l0ng #1 最后直接 cloneNode 了.一阵折腾,终于做出了个成品:https://greasyfork.org/zh-CN/scripts/371548-%E7%9F%A5%E4%B9%8E%E7%9C%8B%E5%9B%BE%E8%84%9A%E6%9C%AC
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2309 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 00:45 · PVG 08:45 · LAX 17:45 · JFK 20:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.