如何编写一个“for 循环”,其中一个 php 值设置一个 html 元素值?

我怎么能if value ==在 for 循环中做,所以我不需要做值 == 检查 10 次?


function getComboA(selectObject) {

    var value = selectObject.value;

    if (value == 1) {

        document.getElementById("selected_slot").value = <?php echo $selected_slot1 ?>;

        document.getElementById("selected_value").value = <?php echo $selected_value1 ?>;

    } else if (value == 2) {

        document.getElementById("selected_slot").value = <?php echo $selected_slot2 ?>;

        document.getElementById("selected_value").value = <?php echo $selected_value2 ?>;

    }


波斯汪
浏览 175回答 1
1回答

偶然的你

制作数组并将其发送给js。<?$arr = [&nbsp; [ 'slot'=> $selected_slot1, 'value'=>&nbsp; $selected_value1 ],&nbsp; [ 'slot'=> $selected_slot2, 'value'=>&nbsp; $selected_value2 ],];&nbsp; &nbsp;?>&nbsp;function getComboA(selectObject) {&nbsp; &nbsp; &nbsp;ar = <? echo json_encode($arr) ?>;&nbsp; &nbsp; &nbsp;var value = selectObject.value;&nbsp; &nbsp; &nbsp;document.getElementById("selected_slot").value = ar[value-1].slot;&nbsp; &nbsp; &nbsp;document.getElementById("selected_value").value = ar[value-1].value}
打开App,查看更多内容
随时随地看视频慕课网APP