<script type="text/javascript">
function SetToBold () {
var state = document.queryCommandState ("bold");
switch (state) {
case true:
alert ("The bold formatting will be removed from the selected text.");
break;
case false:
alert ("The selected text will be displayed in bold.");
break;
case null:
alert ("The state of the 'bold' command is indeterminable.");
break;
}
document.execCommand ('bold', true, null);
}
</script>
document 的execCommand 命令非常的强大,基本可以满足android,IOS端对HTML的一系列操作,例如,Bold,Underline,Italic 等等
document queryCommandState 可以查询某操作的状态,是否开启。