3

我正在尝试在页面上选择多个类并将其更改aria-checked="false"aria-checked="true". 这是我现在使用的脚本:

elms=document.getElementsByClassName("d-va-p a-f-e");
for (i=0;i<elms.length;i++){
    if(elms[i].getAttribute("aria-checked")="false")
        elms[i].getAttribute("aria-checked")="true"
};

源代码如下。课程是“d-va-p afe”。

<div class="d-va-p a-f-e" style="-webkit-user-select: none;" role="option" tabindex="-1" aria-checked="false" id=":89">
    <div class="a-f-e" style="-webkit-user-select: none;">
        <div class="d-va-p-Fe a-f-e" style="-webkit-user-select: none;">
            <img src="https://lh4.googleusercontent.com/-FxDBvNDkbj4/AAAAAAAAAAI/AAAAAAAAAAA/q4f7Fc7OF6A/s48-c/photo.jpg" class="d-va-p-Z a-f-e">
        </div>
        <div class="a-f-e d-va-p-yda" style="-webkit-user-select: none;">
            <div class="d-va-p-Ec a-f-e" style="-webkit-user-select: none;">Herb Smith</div>
        </div>
    </div>
    <div class="d-va-p-iI-oc" style="-webkit-user-select: none;">
        <span class="a-f-e d-J-Eb-v-YA-Me" style="-webkit-user-select: none;"></span>
    </div>
</div>
4

1 回答 1

6

I see two problems. First, you're using assignment instead of comparison. So

if(elms[i].getAttribute("aria-checked")="false")

should be:

if(elms[i].getAttribute("aria-checked")=="false")

Second, your attempt to set the attribute's value won't work. Try this:

elms[i].setAttribute("aria-checked", true);
于 2013-01-04T12:09:19.447 回答