Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用javascript选择所有选项A单选按钮_Javascript_Jquery_Html_Radio Button_Radio Group - Fatal编程技术网

使用javascript选择所有选项A单选按钮

使用javascript选择所有选项A单选按钮,javascript,jquery,html,radio-button,radio-group,Javascript,Jquery,Html,Radio Button,Radio Group,如果从顶部选择了选项4星,我希望表单中的所有选项4星都被选中。如果从顶部选择了选项3星,则应选择所有3星。我尝试使用此代码,但不适用于我 <div class="container con"> <div class="row"> <div class="col-sm-8 col1" ><table cellpadding="13">

如果从顶部选择了选项4星,我希望表单中的所有选项4星都被选中。如果从顶部选择了选项3星,则应选择所有3星。我尝试使用此代码,但不适用于我

            <div class="container con">
               <div class="row">
                    <div class="col-sm-8 col1" ><table cellpadding="13">
                        <tr><td>1.Technical Skills</td></tr>
                        <tr><td>2.Sincerity, Commitment, Regularity, and Punctuality</td></tr>
                        <tr><td>3.Ability to clarify doubts, and teaching with relevant examples</td></tr>
                        <tr><td>4.Accessibility of teachers for doubts and clarifications outside the class</td></tr>
                        <tr><td>5.Ability to command and control the class including evaluation / examination</td></tr>
                    </table>


                </div>
                    <div class="col-sm-4 col2" align="center"><table class="table1"><tr ><td id="rate-area-1">
                            <input type="radio" id="q14" name="q1" value="4" onchange="valueChanged()"/><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q13" name="q1" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q12" name="q1" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q11" name="q1" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                            </td></tr>
                            <tr ><td class="rate-area-2">
                            <input type="radio" id="q24" name="q2" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q23" name="q2" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q22" name="q2" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q21" name="q2" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                        <tr ><td class="rate-area">
                            <input type="radio" id="q34" name="q3" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q33" name="q3" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q32" name="q3" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q31" name="q3" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q44" name="q4" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q43" name="q4" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q42" name="q4" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q41" name="q4" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q54" name="q5" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q53" name="q5" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q52" name="q5" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q51" name="q5" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr></table>
Javascript:

function valueChanged() {
    if(document.getElementById("four").checked == true) {
        document.getElementById("q14").checked = true;
        document.getElementById("q24").checked = true;
        document.getElementById("q34").checked = true;
        document.getElementById("q44").checked = true;
        document.getElementById("q54").checked = true;
        } 

else if(document.getElementById("three").checked == true) {
        document.getElementById("q13").checked = true;
        document.getElementById("q23").checked = true;
        document.getElementById("q33").checked = true;
        document.getElementById("q43").checked = true;
        document.getElementById("q53").checked = true;
        }

else if(document.getElementById("two").checked == true) {
        document.getElementById("q12").checked = true;
        document.getElementById("q22").checked = true;
        document.getElementById("q32").checked = true;
        document.getElementById("q42").checked = true;
        document.getElementById("q52").checked = true;
        }

else if(document.getElementById("one").checked == true) {
        document.getElementById("q11").checked = true;
        document.getElementById("q21").checked = true;
        document.getElementById("q31").checked = true;
        document.getElementById("q41").checked = true;
        document.getElementById("q51").checked = true;

    }
     else{
        return null;
    }`
            <div class="container con">
               <div class="row">
                    <div class="col-sm-8 col1" ><table cellpadding="13">
                        <tr><td>1.Technical Skills</td></tr>
                        <tr><td>2.Sincerity, Commitment, Regularity, and Punctuality</td></tr>
                        <tr><td>3.Ability to clarify doubts, and teaching with relevant examples</td></tr>
                        <tr><td>4.Accessibility of teachers for doubts and clarifications outside the class</td></tr>
                        <tr><td>5.Ability to command and control the class including evaluation / examination</td></tr>
                    </table>


                </div>
                    <div class="col-sm-4 col2" align="center"><table class="table1"><tr ><td id="rate-area-1">
                            <input type="radio" id="q14" name="q1" value="4" onchange="valueChanged()"/><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q13" name="q1" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q12" name="q1" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q11" name="q1" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                            </td></tr>
                            <tr ><td class="rate-area-2">
                            <input type="radio" id="q24" name="q2" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q23" name="q2" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q22" name="q2" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q21" name="q2" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                        <tr ><td class="rate-area">
                            <input type="radio" id="q34" name="q3" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q33" name="q3" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q32" name="q3" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q31" name="q3" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q44" name="q4" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q43" name="q4" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q42" name="q4" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q41" name="q4" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q54" name="q5" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q53" name="q5" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q52" name="q5" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q51" name="q5" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr></table>

            <div class="container con">
               <div class="row">
                    <div class="col-sm-8 col1" ><table cellpadding="13">
                        <tr><td>1.Technical Skills</td></tr>
                        <tr><td>2.Sincerity, Commitment, Regularity, and Punctuality</td></tr>
                        <tr><td>3.Ability to clarify doubts, and teaching with relevant examples</td></tr>
                        <tr><td>4.Accessibility of teachers for doubts and clarifications outside the class</td></tr>
                        <tr><td>5.Ability to command and control the class including evaluation / examination</td></tr>
                    </table>


                </div>
                    <div class="col-sm-4 col2" align="center"><table class="table1"><tr ><td id="rate-area-1">
                            <input type="radio" id="q14" name="q1" value="4" onchange="valueChanged()"/><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q13" name="q1" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q12" name="q1" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q11" name="q1" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                            </td></tr>
                            <tr ><td class="rate-area-2">
                            <input type="radio" id="q24" name="q2" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q23" name="q2" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q22" name="q2" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q21" name="q2" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                        <tr ><td class="rate-area">
                            <input type="radio" id="q34" name="q3" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q33" name="q3" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q32" name="q3" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q31" name="q3" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q44" name="q4" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q43" name="q4" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q42" name="q4" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q41" name="q4" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q54" name="q5" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q53" name="q5" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q52" name="q5" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q51" name="q5" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr></table>
HTML: 四星 三星 双星 一颗星

            <div class="container con">
               <div class="row">
                    <div class="col-sm-8 col1" ><table cellpadding="13">
                        <tr><td>1.Technical Skills</td></tr>
                        <tr><td>2.Sincerity, Commitment, Regularity, and Punctuality</td></tr>
                        <tr><td>3.Ability to clarify doubts, and teaching with relevant examples</td></tr>
                        <tr><td>4.Accessibility of teachers for doubts and clarifications outside the class</td></tr>
                        <tr><td>5.Ability to command and control the class including evaluation / examination</td></tr>
                    </table>


                </div>
                    <div class="col-sm-4 col2" align="center"><table class="table1"><tr ><td id="rate-area-1">
                            <input type="radio" id="q14" name="q1" value="4" onchange="valueChanged()"/><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q13" name="q1" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q12" name="q1" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q11" name="q1" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                            </td></tr>
                            <tr ><td class="rate-area-2">
                            <input type="radio" id="q24" name="q2" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q23" name="q2" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q22" name="q2" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q21" name="q2" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                        <tr ><td class="rate-area">
                            <input type="radio" id="q34" name="q3" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q33" name="q3" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q32" name="q3" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q31" name="q3" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q44" name="q4" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q43" name="q4" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q42" name="q4" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q41" name="q4" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q54" name="q5" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q53" name="q5" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q52" name="q5" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q51" name="q5" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr></table>

1.技术技能
2.真诚、承诺、规律和守时
3.能够澄清疑问,并用相关示例进行教学
4.教师可在课堂外进行质疑和澄清
5.指挥和控制课堂的能力,包括评估/考试
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星

请在这里帮助我编写一些javascript新代码

您显示的图片和您发布的代码以某种方式显示了两种不同的东西。添加最上面一行的输入元素,并为它们指定
onchange=“valueChanged()”
(由于某些原因,并非所有的四星按钮都像现在这样)然后它就可以工作了

            <div class="container con">
               <div class="row">
                    <div class="col-sm-8 col1" ><table cellpadding="13">
                        <tr><td>1.Technical Skills</td></tr>
                        <tr><td>2.Sincerity, Commitment, Regularity, and Punctuality</td></tr>
                        <tr><td>3.Ability to clarify doubts, and teaching with relevant examples</td></tr>
                        <tr><td>4.Accessibility of teachers for doubts and clarifications outside the class</td></tr>
                        <tr><td>5.Ability to command and control the class including evaluation / examination</td></tr>
                    </table>


                </div>
                    <div class="col-sm-4 col2" align="center"><table class="table1"><tr ><td id="rate-area-1">
                            <input type="radio" id="q14" name="q1" value="4" onchange="valueChanged()"/><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q13" name="q1" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q12" name="q1" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q11" name="q1" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                            </td></tr>
                            <tr ><td class="rate-area-2">
                            <input type="radio" id="q24" name="q2" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q23" name="q2" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q22" name="q2" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q21" name="q2" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                        <tr ><td class="rate-area">
                            <input type="radio" id="q34" name="q3" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q33" name="q3" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q32" name="q3" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q31" name="q3" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q44" name="q4" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q43" name="q4" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q42" name="q4" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q41" name="q4" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q54" name="q5" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q53" name="q5" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q52" name="q5" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q51" name="q5" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr></table>
函数值已更改(){
if(document.getElementById(“四”).checked==true){
document.getElementById(“q14”).checked=true;
document.getElementById(“q24”).checked=true;
document.getElementById(“q34”).checked=true;
document.getElementById(“q44”).checked=true;
document.getElementById(“q54”).checked=true;
} 
else if(document.getElementById(“三”).checked==true){
document.getElementById(“q13”).checked=true;
document.getElementById(“q23”).checked=true;
document.getElementById(“q33”).checked=true;
document.getElementById(“q43”).checked=true;
document.getElementById(“q53”).checked=true;
}
else if(document.getElementById(“两”).checked==true){
document.getElementById(“q12”).checked=true;
document.getElementById(“q22”).checked=true;
document.getElementById(“q32”).checked=true;
document.getElementById(“q42”).checked=true;
document.getElementById(“q52”).checked=true;
}
else if(document.getElementById(“一”).checked==true){
document.getElementById(“q11”).checked=true;
document.getElementById(“q21”).checked=true;
document.getElementById(“q31”).checked=true;
document.getElementById(“q41”).checked=true;
document.getElementById(“q51”).checked=true;
}
否则{
返回null;
}
}

四星
三星
双星
一颗星
1.技术技能
2.真诚、承诺、规律和守时
3.能够澄清疑问,并用相关示例进行教学
4.教师可在课堂外进行质疑和澄清
5.指挥和控制课堂的能力,包括评估/考试
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星

使用事件委派会更优雅-检查其容器中单击的目标的索引,然后选择其容器中该索引的所有
输入,然后
检查它们:

            <div class="container con">
               <div class="row">
                    <div class="col-sm-8 col1" ><table cellpadding="13">
                        <tr><td>1.Technical Skills</td></tr>
                        <tr><td>2.Sincerity, Commitment, Regularity, and Punctuality</td></tr>
                        <tr><td>3.Ability to clarify doubts, and teaching with relevant examples</td></tr>
                        <tr><td>4.Accessibility of teachers for doubts and clarifications outside the class</td></tr>
                        <tr><td>5.Ability to command and control the class including evaluation / examination</td></tr>
                    </table>


                </div>
                    <div class="col-sm-4 col2" align="center"><table class="table1"><tr ><td id="rate-area-1">
                            <input type="radio" id="q14" name="q1" value="4" onchange="valueChanged()"/><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q13" name="q1" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q12" name="q1" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q11" name="q1" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                            </td></tr>
                            <tr ><td class="rate-area-2">
                            <input type="radio" id="q24" name="q2" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q23" name="q2" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q22" name="q2" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q21" name="q2" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                        <tr ><td class="rate-area">
                            <input type="radio" id="q34" name="q3" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q33" name="q3" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q32" name="q3" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q31" name="q3" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q44" name="q4" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q43" name="q4" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q42" name="q4" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q41" name="q4" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr>
                            <tr ><td class="rate-area">
                            <input type="radio" id="q54" name="q5" value="4" onchange="valueChanged()" /><label for="4-star" title="Very Good">4 stars</label>
                            <input type="radio" id="q53" name="q5" value="3" /><label for="3-star" title="Good">3 stars</label>
                            <input type="radio" id="q52" name="q5" value="2" /><label for="2-star" title="Satisfactory">2 stars</label>
                            <input type="radio" id="q51" name="q5" value="1" /><label for="1-star" title="Unsatisfactory">1 star</label>
                        </td></tr></table>
consttable1=document.querySelector('.table1');
表1.addEventListener('change',(e)=>{
常数{target}=e;
const{children}=target.parentElement;
如果(!target.matches('#rate-area-1输入[type=“radio”]”)返回;
//获取已更改输入的索引:
const index=Array.prototype.indexOf.call(子级,目标);
常量选择器='输入:第n个子项('+(索引+1)+')'
表1.查询选择器all(选择器)
.forEach(输入=>input.checked=true);
});

四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星
四星
三星
双星
一颗星

关于“它对我不起作用”的含义,你能提供更多的细节吗?怎么搞的?您的函数是否执行了?你有错误吗?等等。我还注意到您有
label for=“4-star”…
,没有id为
4-star
的输入(这对于所有的“n-star”都是正确的)。for
属性应该与另一个元素的id正确匹配