La copia del código es la siguiente:
<script language = "javaScript">
Test de funciones ()
{
var rng = document.body.createTextrange ();
alerta (rng.text)
}
FUNCIÓN TEST1 ()
{
var rng = document.body.createTextrange ();
alerta (rng.htmlText)
}
</script>
<input type = "button" onClick = "test ()" value = "text">
<input type = "button" onClick = "test1 ()" value = "htmlText">
Obtenga el texto seleccionado en el cuadro de texto especificado: solo responda al primer cuadro de texto
La copia del código es la siguiente:
<input id = "inp1" type = "text" value = "1234567890">
<input id = "inp2" type = "text" value = "9876543210">
<input type = "button" onClick = "test ()" value = "ok">
<script language = "javaScript">
Test de funciones ()
{
var o = document.getElementById ("inp1")
var r = document.selection.CreaterGe ();
if (O.CreateTextrange (). Inrange (R))
alerta (r.text);
}
</script>
Búsqueda inversa del texto de la página
La copia del código es la siguiente:
abababababababa
<input value = "Reverse Order Find A" onClick = myFindText ("A") type = "Botón">
<script language = 'javaScript'>
var rng = document.body.createTextrange ();
función myfindText (texto)
{
rng.ocollapse (falso);
if (rng.findText (texto, -1,1))
{
rng.select ();
rng.ocollapse (verdadero);
}demás
{alerta ("final");}
}
</script>
Concéntrese en el control y pon el cursor al final
La copia del código es la siguiente:
<script language = "javaScript">
función setFocus ()
{
var obj = Event.SrCelement;
var txt = obj.createTextrange ();
txt.movestart ('carácter', obj.value.length);
txt.ocollapse (verdadero);
txt.select ();
}
</script>
<input type = "text" value = "http://toto369.net" onfocus = "setFocus ()">
Obtenga la posición del cursor en el cuadro de texto
La copia del código es la siguiente:
<script language = "javaScript">
function getPos (obj) {
obj.focus ();
var s = document.selection.CreaterGe ();
S.SetEndpoint ("StartTostart", obj.createTextrange ())
alerta (s.text.length);
}
</script>
<input type = "text" id = "txt1" valor = "1234567890">
<input type = "button" value = "getCursor Position" onClick = getPos (txt1)>
Controlar la posición del cursor en el cuadro de entrada
La copia del código es la siguiente:
<script language = "javaScript">
funciones setpos (num)
{
text1.focus ();
var e = document.getElementById ("text5");
var r = e.createTextrange ();
r.movestart ('carácter', num);
R.Collapse (verdadero);
r.select ();
}
</script>
<input type = "text" id = "text5" value = "1234567890">
<select onchange = "setpos (this.selectedIndex)">
<opción valor = "0"> 0 </opción>
<opción valor = "1"> 1 </opción>
<opción valor = "2"> 2 </opción>
<opción valor = "3"> 3 </opción>
<opción valor = "4"> 4 </opción>
<opción valor = "5"> 5 </opción>
<opción valor = "6"> 6 </opción>
<opción valor = "7"> 7 </opción>
</select>
Seleccione un párrafo de texto en el cuadro de texto
La copia del código es la siguiente:
<Script Language = JavaScript>
función sel (obj, num)
{
var rng = obj.createTextrange ()
var sel = rng.duplicate ();
sel.movestart ("carácter", num);
Sel.SetEndpoint ("EndTtarSart", rng);
sel.select ();
}
</script>
<input type = "text" id = "text1" value = "1234567890">
<select onchange = "sel (text1, this.value)">
<opción valor = "0"> 0 </opción>
<opción valor = "1"> 1 </opción>
<opción valor = "2"> 2 </opción>
<opción valor = "3"> 3 </opción>
<opción valor = "4"> 4 </opción>
<opción valor = "5"> 5 </opción>
<opción valor = "6"> 6 </opción>
<opción valor = "7"> 7 </opción>
</select>
Controlar el movimiento del cursor en el cuadro de texto
La copia del código es la siguiente:
<input type = "button" value = "<" onClick = Go (-1)>
<input id = "demo" valor = "aquí es texto">
<input type = "button" value = ">" onClick = Go (1)>
<script language = "javaScript">
función go (n) {
demo.focus ();
con (document.selection.createrange ())
{
Movestart ("Carácter", n);
colapsar();
seleccionar();
}
}
</script>