我们在做后台发布文章或者输入的时候,通常用复文本框,我前面文章总结了前端常用的复文本,但是,我们在前台用户输入的时候,通常限制复文本的输入,当然,你也可以允许用户用复文本,不过要在提交的时候或者后台对提交的内容进行过滤或者审核。
下面我们来总结一下前端js复文本常用的函数。
下面是斜体、下划线、居中、粗体,插入图片、创建工具条的函数
//斜体
function italicize(obj) {
if (document.selection && document.selection.type == "Text") {
AddTxt="[i]"+text+"[/i]";
AddText(obj,AddTxt);
} else {
txt=prompt('文字将变斜体','文字');
if (txt!=null) {
AddTxt="[i]"+txt+"[/i]";
AddText(obj,AddTxt);
}
}
}
//下划线
function underline(obj) {
if (document.selection && document.selection.type == "Text") {
AddTxt="[u]"+text+"[/u]";
AddText(obj,AddTxt);
} else {
txt=prompt('下划线文字','文字');
if (txt!=null) {
AddTxt="[u]"+txt+"[/u]";
AddText(obj,AddTxt);
}
}
}
//居中
function center(obj) {
if (document.selection && document.selection.type == "Text") {
AddTxt="[align=center]"+text+"[/align]";
AddText(obj,AddTxt);
} else {
txt2=prompt('对齐样式\n输入 ’center’ 表示居中, ’left’ 表示左对齐, ’right’ 表示右对齐.',"center");
while ((txt2!="") && (txt2!="center") && (txt2!="left") && (txt2!="right") && (txt2!=null)) {
txt2=prompt('错误!\n类型只能输入 ’center’ 、 ’left’ 或者 ’right’.',"");
}
txt=prompt('要对齐的文本','文字');
if (txt!=null) {
AddTxt="[align="+txt2+"]"+txt+"[/align]";
AddText(obj,AddTxt);
}
}
}
//粗体
function bold(obj) {
if (document.selection && document.selection.type == "Text") {
AddTxt="[b]"+text+"[/b]";
AddText(obj,AddTxt);
} else {
txt=prompt('文字将被变粗.','文字');
if (txt!=null) {
AddTxt="[b]"+txt+"[/b]";
AddText(obj,AddTxt);
}
}
}
//插入图片
function insimg(obj){
if (document.selection && document.selection.type == "Text") {
AddTxt="[img]"+text+"[/img]";
AddText(obj,AddTxt);
} else {
txt=prompt('请输入图片完整URL地址:','http://');
if (txt!=null) {
AddTxt="[img]"+txt+"[/img]";
AddText(obj,AddTxt);
}
}
}