- 獲取文本框裡鼠標選取到的文字
Html代碼
- <textarea rows="10" cols="50" id="t1">
- 請問如何獲得 文本框裡 鼠標選取到的文字?
- textarea>
- <br>
- <button onClick="if (document.selection.createRange().text != '') t1.value = t1.value.replace(document.selection.createRange().text, '' + document.selection.createRange().text + '')"><b> B b>button>
- <button onClick="if (document.selection.createRange().text != '') t1.value = t1.value.replace(document.selection.createRange().text, '' + document.selection.createRange().text + '')"><i> I i>button>
- 複選框的全選,多選,全不選,反選
Html代碼
- <form name=hrong>
- <input type=checkbox name=All onclick="checkAll('mm')">全選<br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/>
- <input type=checkbox name=mm onclick="checkItem('All')"><br/><br/>
- <input type=checkbox name=All2 onclick="checkReverse('mm2')">反選<br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=mm2 onclick="checkItem('All2')"><br/>
- <input type=checkbox name=All3 onclick="checkItem('mm3')">特選<br/>
- <input type=checkbox name=mm3 onclick="checkItem('All3')"><br/>
- form>
- <SCRIPT LANGUAGE="JavaScript">
- function checkAll(str)
- {
- var a = document.getElementsByName(str);
- var n = a.length;
- for (var i=0; i<n; i++)
- a[i].checked = window.event.srcElement.checked;
- }
- function checkReverse(str)
- {
- var a = document.getElementsByName(str);
- var n = a.length;
- for (var i=0; i<n; i++)
- a[i].checked = !a[i].checked;
- }
- function checkItem(str)
- {
- var e = window.event.srcElement;
- var all = eval("document.hrong."+ str);
- if (e.checked)
- {
- var a = document.getElementsByName(e.name);
- all.checked = true;
- for (var i=0; i<a.length; i++)
- {
- if (!a[i].checked){ all.checked = false; break;}
- }
- }
- else all.checked = false;
- }
- SCRIPT>
- 滾動條滾動至最底端:
Javascript代碼
- document.body.scrollTop = document.body.scrollHeight;
- document.body.scrollTop = document.body.scrollHeight;