การคัดลอกรหัสมีดังนี้:
<ภาษาสคริปต์ = "JavaScript">
การทดสอบฟังก์ชั่น ()
-
var rng = document.body.createTextrange ();
การแจ้งเตือน (rng.text)
-
ฟังก์ชั่น test1 ()
-
var rng = document.body.createTextrange ();
การแจ้งเตือน (rng.htmltext)
-
</script>
<อินพุต type = "ปุ่ม" onclick = "test ()" value = "text">
<อินพุต type = "ปุ่ม" onclick = "test1 ()" value = "htmltext">
รับข้อความที่เลือกในกล่องข้อความที่ระบุ: ตอบสนองต่อกล่องข้อความแรกเท่านั้น
การคัดลอกรหัสมีดังนี้:
<อินพุต id = "inp1" type = "text" value = "1234567890">
<อินพุต id = "inp2" type = "text" value = "9876543210">
<อินพุต type = "ปุ่ม" onclick = "test ()" value = "ตกลง">
<ภาษาสคริปต์ = "JavaScript">
การทดสอบฟังก์ชั่น ()
-
var o = document.getElementById ("inp1")
var r = document.selection.createrange ();
if (O.CreateTexTrange (). inRange (r))
การแจ้งเตือน (R.Text);
-
</script>
ย้อนกลับการค้นหาข้อความหน้าเว็บ
การคัดลอกรหัสมีดังนี้:
Abababababababababa
<ค่าอินพุต = "reverse order ค้นหา" onClick = myFindText ("a") type = "ปุ่ม">
<ภาษาสคริปต์ = 'JavaScript'>
var rng = document.body.createTextrange ();
ฟังก์ชั่น myFindText (ข้อความ)
-
rng.collapse (เท็จ);
if (rng.findtext (text, -1,1))
-
rng.select ();
rng.collapse (จริง);
}อื่น
{Alert ("end");}
-
</script>
มุ่งเน้นไปที่การควบคุมและวางเคอร์เซอร์จนจบ
การคัดลอกรหัสมีดังนี้:
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชั่น setFocus ()
-
var obj = event.srcelement;
var txt = obj.createTextrange ();
txt.movestart ('ตัวละคร', obj.value.length);
txt.collapse (จริง);
txt.select ();
-
</script>
<input type = "text" value = "http://toto369.net" onfocus = "setFocus ()">>
รับตำแหน่งเคอร์เซอร์ในกล่องข้อความ
การคัดลอกรหัสมีดังนี้:
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชั่น getpos (obj) {
obj.focus ();
var s = document.selection.createrange ();
S.SetEndpoint ("StartTostart", OBJ.CreateTexTrange ())
การแจ้งเตือน (s.text.length);
-
</script>
<อินพุต type = "text" id = "txt1" value = "1234567890">>
<อินพุต type = "ปุ่ม" value = "ตำแหน่ง getCursor" onClick = getPos (txt1)>>
ควบคุมตำแหน่งเคอร์เซอร์ในกล่องอินพุต
การคัดลอกรหัสมีดังนี้:
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชัน setpos (num)
-
text1.focus ();
var e = document.getElementById ("text5");
var r = e.createtextrange ();
R.Movestart ('ตัวละคร', NUM);
R.Collapse (จริง);
R.Select ();
-
</script>
<อินพุต type = "text" id = "text5" value = "1234567890">>
<เลือก onChange = "setPos (this.selectedIndex)">
<ตัวเลือกค่า = "0"> 0 </potion>
<ตัวเลือกค่า = "1"> 1 </potion>
<ตัวเลือกค่า = "2"> 2 </potion>
<ตัวเลือกค่า = "3"> 3 </potion>
<ตัวเลือกค่า = "4"> 4 </potion>
<ตัวเลือกค่า = "5"> 5 </potion>
<ตัวเลือกค่า = "6"> 6 </potion>
<ตัวเลือกค่า = "7"> 7 </potion>
</เลือก>
เลือกย่อหน้าของข้อความในกล่องข้อความ
การคัดลอกรหัสมีดังนี้:
<ภาษาสคริปต์ = JavaScript>
ฟังก์ชั่น SEL (OBJ, NUM)
-
var rng = obj.createTextrange ()
var sel = rng.duplicate ();
Sel.Movestart ("อักขระ", num);
sel.setendpoint ("endtostart", rng);
sel.select ();
-
</script>
<อินพุต type = "text" id = "text1" value = "1234567890">>
<เลือก onChange = "sel (text1, this.value)">
<ตัวเลือกค่า = "0"> 0 </potion>
<ตัวเลือกค่า = "1"> 1 </potion>
<ตัวเลือกค่า = "2"> 2 </potion>
<ตัวเลือกค่า = "3"> 3 </potion>
<ตัวเลือกค่า = "4"> 4 </potion>
<ตัวเลือกค่า = "5"> 5 </potion>
<ตัวเลือกค่า = "6"> 6 </potion>
<ตัวเลือกค่า = "7"> 7 </potion>
</เลือก>
ควบคุมการเคลื่อนไหวของเคอร์เซอร์ในกล่องข้อความ
การคัดลอกรหัสมีดังนี้:
<อินพุต type = "button" value = "<" onclick = go (-1)>
<อินพุต id = "demo" value = "นี่คือข้อความ">
<อินพุต type = "button" value = ">" onclick = go (1)>
<ภาษาสคริปต์ = "JavaScript">
ฟังก์ชั่นไป (n) {
demo.focus ();
ด้วย (document.selection.createrange ())
-
movestart ("ตัวละคร", n);
ทรุด();
เลือก();
-
-
</script>