css 手机上的选项不会改变,只有电脑上的选项会改变

drkbr07n  于 2023-01-18  发布在  其他
关注(0)|答案(1)|浏览(161)

我用javascript创建了一个函数,它可以根据我在上一次select中选择的值来改变select中选项的数量,这个函数在电脑上正常工作,但是当我在我的手机和其他人的手机上使用它时,这个函数就不工作了
这些是选择:

<select class='opcoes' id="pecasDoJogo-1Auto" onchange="getValue('pecasDoJogo-1Auto')" onclick="changeQuantityOfOptions('pecasDoJogo-1Auto','pecasDoJogo-1TeleOp')">
                        <option value="0" >0</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                    </select> 

<select class='opcoes' id="pecasDoJogo-1TeleOp" onchange="getValue('pecasDoJogo-1TeleOp')" onclick="changeQuantityOfOptions('pecasDoJogo-1TeleOp','pecasDoJogo-1Auto')">
                        <option value="0">0</option>
                        <option value="1" >1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                    </select>

下面是我正在使用的函数:

function getValue(nameId){
    return parseInt(document.getElementById(nameId).value)
}

function changeQuantityOfOptions(yourId,ReferenceId){
        const quantidade = 9 - parseInt(document.getElementById(yourId).value)
        const select = document.getElementById(ReferenceId)
        select.innerHTML = ""
        for(var i = 0; i <= quantidade; i++){
            select.innerHTML += `<option value="${i}">${i}</option>`
        }
}```
hc2pp10m

hc2pp10m1#

您应该只调用函数onchange,而不是onclick

function getValue(nameId){
    return parseInt(document.getElementById(nameId).value)
}

function changeQuantityOfOptions(yourId,ReferenceId){
        const quantidade = 9 - parseInt(document.getElementById(yourId).value)
        const select = document.getElementById(ReferenceId)
        select.innerHTML = ""
        for(var i = 0; i <= quantidade; i++){
            select.innerHTML += `<option value="${i}">${i}</option>`
        }
}
<select class='opcoes' id="pecasDoJogo-1Auto" onchange="changeQuantityOfOptions('pecasDoJogo-1Auto','pecasDoJogo-1TeleOp')">
                        <option value="0" >0</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                    </select> 

<select class='opcoes' id="pecasDoJogo-1TeleOp" onchange="changeQuantityOfOptions('pecasDoJogo-1TeleOp','pecasDoJogo-1Auto')">
                        <option value="0">0</option>
                        <option value="1" >1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                        <option value="6">6</option>
                        <option value="7">7</option>
                        <option value="8">8</option>
                        <option value="9">9</option>
                    </select>

相关问题