这里是一个非常简单的jQuery修复隐藏是一个标签标记的任何儿童的投入:
<p>Would you prefer to walk without effort?</p>
<input type="radio" value="a" name="radgrp2"/> Yes <br />
<input type="radio" value="b" name="radgrp2"/> No <br />
<input type="radio" value="c" name="radgrp2" id="rad[1]" style="display:none;"/>
<label for="rad[1]"><input type="button"value="Clear"/></label>
<script>
$("label>input").hide();
</script>
这里试试:http://jsfiddle.net/VA3EH/1/
这通过在元素上调用show()也很容易反转。
这里是这样做一个漂亮的,动态的方式:
<p>Would you prefer to walk without effort?</p>
<input type="radio" value="a" name="radgrp2"/> Yes <br />
<input type="radio" value="b" name="radgrp2"/> No <br />
<input type="radio" value="c" name="radgrp2" id="rad[1]" style="display:none;"/>
<label for="rad[1]"><input type="button"value="Clear"/></label>
<script>
$("label>input").hide();
$("input[type='radio']").click(function() {
$(this).nextAll("label").find("input").show();
})
</script>
按钮被隐藏,单选按钮直到点击。一旦单选按钮,然后清除按钮显示。试试看:http://jsfiddle.net/25z3h/
然后,如果你真的想获得幻想,另附事件处理程序的按钮,以清除该复选框值,并再次隐藏自身:
<p>Would you prefer to walk without effort?</p>
<input type="radio" value="a" name="radgrp2"/> Yes <br />
<input type="radio" value="b" name="radgrp2"/> No <br />
<input type="radio" value="c" name="radgrp2" id="rad[1]" style="display:none;"/>
<label for="rad[1]"><input type="button"value="Clear"/></label>
<script>
$("label>input").hide();
$("input[type='radio']").click(function() {
$(this).nextAll("label").find("input").show();
$(this).nextAll("label").find("input").click(function() {
$(this).parent("label").prevAll("input[type='radio']").removeAttr("checked");
$(this).hide();
})
})
</script>
这里试试:http://jsfiddle.net/VA3EH/2/
[可怜的灵魂处理死浏览器。](http://www.modern.ie/en-us/ie6countdown)是否真的没有空间ID和名称?如果你删除了按钮,它是否工作? – epascarello
@epascarello在删除标签后,它可以工作。不过,我需要使它与Label一起工作。 – swapna
我可以问你为什么要为IE6写东西吗?它已经过时了7年,而且截至2014年4月将不再受到微软的支持......现在是时候继续我的想法了。 –