例如,如果您选择带有id="chocolate-yes"
或id="vanilla-yes"
的选项,带有 的选项id="icecreamcone-yes"
也将被选中。
任何人都知道可以做到这一点的Javascript?
注1:带有的选项id="sprinkles-yes"
不生效id="icecreamcone-yes"
。
注意 2:id 名称不能更改,也不能为元素添加更多属性。
注意 3:不能使用 jQuery。
<ul id="icecream" style="list-style:none;line-height:30px;">
<li>
<select id="icecreamcone">
<option value="addicecreamcone">Would you like an ice cream cone?</option>
<option id="icecreamcone-yes" value="yes">Yes</option>
<option id="icecreamcone-no" value="no">No thanks</option>
</select>
</li>
<li>
<select id="vanilla">
<option value="addvanilla">Would you like to add vanilla ice cream?</option>
<option id="vanilla-yes" value="yes">Yes</option>
<option id="vanilla-no" value="no">No thanks</option>
</select>
</li>
<li>
<select id="chocolate">
<option value="addchocolate">Would you like to add chocolate ice cream?</option>
<option id="chocolate-yes" value="yes">Yes</option>
<option id="chocolate-no" value="no">No thanks</option>
</select>
</li>
<li>
<select id="sprinkles">
<option value="addsprinkles">Would you like to add sprinkles on top?</option>
<option id="sprinkles-yes" value="yes">Yes</option>
<option id="sprinkles-no" value="no">No thanks</option>
</select>
</li>
</ul>