- 爱易网页
-
JavaSript
- JS脚本语言,怎么定位在两个不同文本框中
日期:2014-05-16 浏览次数:20451 次
JS脚本语言,如何定位在两个不同文本框中?
var helpstat = false;
var basic = false;
var text = " ";
var AddTxt = " ";
var word= "文字 ";
var userAgent = navigator.userAgent.toLowerCase();
var is_ie = userAgent.indexOf( 'msie ') != -1;
var mydocum;
function init(){
mydocum=document.myform.mytext;
}
//function enable(btn){btn.filters.gray.enabled=0;}
//function disable(btn){btn.filters.gray.enabled=1;}
function bold() {
if (helpstat) {alert( "加粗标记\n使文本加粗.\n用法: [b]这是加粗的文字[/b] ");
}
else if (basic) {
lycode( "b ", " ", " ", " ");
}
else {
lycode( "b ", " ", "文字将被变粗. ",word);
}
}
function getActiveText() {
setfocus();
if (!is_ie || (is_ie && !document.selection)) {
return false;
}
var sel = document.selection;
var rng = sel.createRange();
rng.colapse;
if (rng != null && (sel.type == "Text " || sel.type == "None ")) {
text = rng.text;
}
if (mydocum.createTextRange) {
mydocum.caretPos = rng.duplicate();
}
return true;
}
function setfocus() {
mydocum.focus();
}
function AddText(NewCode) {
if (typeof(mydocum.createTextRange) != "undefined " && mydocum.caretPos) {
var caretPos = mydocum.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
} else {
mydocum.value += NewCode;
}
setfocus();
getActiveText();
AddTxt = " ";
}
function lycode(lycode, optioncompiled, prompttip, prompttext) {
if(optioncompiled!= ' ') {