如何获得js代码的accesskey值选项?

时间:2014-06-28 16:24:57

标签: javascript

document.getElementById('if-font').innerHTML ='
<a href="http://example.com/?city='**  accesskey  **'"> 
http://example.com/?city='+cityName+'</a>';

    <select name="citySelect" id="citySelect" onchange="selectChanged()" >
        <option selected>Please Select</option>
        <option value="xml/16702.xml" accessKey ="ZZZX">ZZZZ</option>

如何获得js代码的选项accesskey值?

我需要显示该链接

http://example.com/?city=ZZZX

2 个答案:

答案 0 :(得分:0)

var accessKey = document.querySelector('option[value="xml/16702.xml"]')
                               .getAttribute("accessKey");

应该可以正常工作。

element.getAttribute

答案 1 :(得分:0)

就是这样:))

        var selected = document.getElementById("citySelect").value;
        var e = document.getElementById("citySelect");
        sehir = e.options[e.selectedIndex].accessKey;