我正在使用DynaTree(code.google/p/dynatree),但是我遇到了一些问题,希望有人可以提供帮助.
I am using The DynaTree (code.google/p/dynatree) but I am having some problems and hoping someone can help..
我在页面上显示树,如下所示:
I am displaying the tree on the page like below:
<div id="tree"> <ul> <li class="folder">Outputs <ul> <li id="item1" data="icon: 'base.gif', url: 'page1.htm', target: 'AccessPage'">Item 1 Title <li id="item2" data="icon: 'base.gif', url: 'page2.htm', target: 'AccessPage'">Item 2 Title <li id="item3" data="icon: 'base.gif', url: 'page3.htm', target: 'AccessPage'">Item 3 Title <li id="item4" data="icon: 'base.gif', url: 'page4.htm', target: 'AccessPage'">Item 4 Title </ul> </ul> </div>但是,无论是否选择使用 JavaScript ,我都试图更改项目上的图标.
However I am trying to change the icon on a item no matter if it's selected or not only using JavaScript.
我要使用的新图标是base2.gif
the new icon I want to use is base2.gif
我尝试使用以下方法,但似乎不起作用:
I have tried using the following but it don't seem to work:
document.getElementById('item1').data = "icon: 'base2.gif', url: 'output.htm', target: 'AccessPage', output: '1'";有人知道我可能在做错什么吗?
anyone know what I might be doing wrong?
推荐答案使用setAttribute方法:
document.getElementById('item1').setAttribute('data', "icon: 'base2.gif', url: 'output.htm', target: 'AccessPage', output: '1'");但是您确实应该使用带有破折号及其属性的数据,例如:
But you really should be using data followed with a dash and with its property, like:
<li ... data-icon="base.gif" ...>要在JS中使用dataset属性,
document.getElementById('item1').dataset.icon = "base.gif";更多推荐
使用JavaScript设置自定义属性
发布评论