【发布时间】:2011-06-16 23:16:15
【问题描述】:
假设我有以下创建两个单选按钮的代码:
<li id="foli517" class=" ">
<label class="desc" id="shippingChoice" for="Field517_0">
Shipping Options
</label>
<div>
<input id="shippingChoice" name="Field517" type="hidden" value="" />
<span>
<input id="shipping1" name="Field517" type="radio" class="field radio" value="$2.00 Shipping Fee" tabindex="13" checked="checked" />
<label class="choice" for="Field517_0" >
$2.00 Shipping Fee</label>
</span>
<span>
<input id="Field517_1" name="Field517" type="radio" class="field radio" value="I will pick up the items (free shipping)" tabindex="14" />
<label class="choice" for="Field517_1" >
I will pick up the items (free shipping)</label>
</span>
</div>
</li>
我将如何实现一个 javascript 函数 onclick,当单击第二个单选按钮时,它会使用单词“FREE”更新 id 为“mySpan”的 span 的内部 html,否则会更新为“NOT FREE”?
document.getElementById(WHAT GOES HERE).onclick = function() {
//what goes here?
};
【问题讨论】:
-
能否改进一下代码格式?
标签: javascript html input onclick radio