我现在有三个复选框和一个文本框如果我在文本框中写一些内容并选中粗体复选框,则文本应以粗体效果显示,并以类似的斜体和下划线显示,而无需回发(即它应立即反映所选效果)。
这是我的代码:
Bold:<input type="checkbox" value=""/>
Italic:<input type="checkbox" value=""/>
Underline:<input type="checkbox" value=""/>
<input type="text" value="">
您可以执行以下操作:
<form>
Bold:<input name="textStyle" type="checkbox" value="bold"/>
Italic:<input name="textStyle" type="checkbox" value="italic"/>
Underline:<input name="textStyle" type="checkbox" value="underline"/>
<input name="styledText" type="text" value="">
</form>
<script type="text/javascript">
$('input[name="textStyle"]').change(function(){
if ($(this).val() == 'bold'){
if ($(this).is(':checked')) $('input[name="styledText"]').css('font-weight', 'bold');
else $('input[name="styledText"]').css('font-weight', 'normal');
}
else if ($(this).val() == 'italic'){
if ($(this).is(':checked')) $('input[name="styledText"]').css('font-style', 'italic');
else $('input[name="styledText"]').css('font-style', 'normal');
}
else if ($(this).val() == 'underline'){
if ($(this).is(':checked')) $('input[name="styledText"]').css('text-decoration', 'underline');
else $('input[name="styledText"]').css('text-decoration', 'none');
}
});
</script>
在这里小提琴:http://jsfiddle.net/tyfsf/ http://jsfiddle.net/tyfsf/
希望能帮助到你!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)