国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
js獲取頁面選中文件 - Terryang - JavaEye技術(shù)網(wǎng)站
Html 代碼
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="content-type" content="text/html; charset=utf-8" />  
  5. <meta name="keywords" content="selection, selectionStart, getSelection, select, input, " />  
  6. <meta name="description" content="在一些特殊應(yīng)用中,我們需要獲取頁面上選中的文字,但是要實現(xiàn)這一需求,我們不得不面對那惱人的兼容 問題,本文介紹了一個兼容性較好的解決方法。同時,也提供了一個在 FireFox 下獲取 input 和 textarea 中選中文字的解決方 案。" />  
  7. <title>Javascript 獲取頁面上選中的文 字 - selection, selectionStart, getSelection, select, input, </title>  
  8. </head>  
  9. <body>  
  10. <div id="example">  
  11. <h3 id="example_title">Javascript 獲取頁面上選中的文字</h3>  
  12. <div id="example_main">  
  13. <!--************************************* 實例代碼開 始 *************************************-->  
  14. <script type="text/javascript">  
  15. function getSelectedText() {  
  16. if (window.getSelection) {  
  17. // This technique is the most likely to be standardized.  
  18. // getSelection() returns a Selection object, which we do not document.  
  19. return window.getSelection().toString();  
  20. }  
  21. else if (document.getSelection) {  
  22. // This is an older, simpler technique that returns a string  
  23. return document.getSelection();  
  24. }  
  25. else if (document.selection) {  
  26. // This is the IE-specific technique.  
  27. // We do not document the IE selection property or TextRange objects.  
  28. return document.selection.createRange().text;  
  29. }  
  30. }  
  31. function getTextFieldSelection(e) {  
  32. if (e.selectionStart != undefined && e.selectionEnd != undefined) {  
  33. var start = e.selectionStart;  
  34. var eend = e.selectionEnd;  
  35. return e.value.substring(start, end);  
  36. }  
  37. else return "";  // Not supported on this browser  
  38. }  
  39. function doGetSelectedText() {  
  40. var text = getSelectedText();  
  41. document.getElementById('output').innerHTML = text;  
  42. }  
  43. function doGetTextFieldSelection() {  
  44. var el = document.getElementById('tempText');  
  45. var text = getTextFieldSelection(el);  
  46. document.getElementById('output').innerHTML = text;  
  47. }  
  48. window.onload = function() {  
  49. document.getElementById('getSelectedText').onclick = doGetSelectedText;  
  50. document.getElementById('getTextFieldSelection').onclick = doGetTextFieldSelection;  
  51. }  
  52. </script>  
  53. <h2>請 選中頁面上的文字后點擊下面的按鈕:</h2>  
  54. <div id="output" style="color:#FF0000;font-weight:bold;"></div>  
  55. <p>在 編程的過程中,我們通常都會積累很多簡單、有效并且可重用的小段代碼,一個簡單的字符串處理函數(shù)或者一個驗證郵件地址的正則表達式,又或者一個簡單的文件 上傳類,甚至一個效果不錯的CSS導航樣式。這些小技巧為我們節(jié)省了不少時間,但是時間一長,代碼數(shù)量越來越多,尋找起來也耗費了不少時間。因此,本站致 力于收集整理一些類似的小知識,并且努力提高文章搜索質(zhì)量,一來方便大家查閱,二來也算是支持一下開源事業(yè)。</p>  
  56. <p>本 站收集的代碼和教程中,有從世界著名開源軟件中摘取的函數(shù)、類,也有網(wǎng)友提交的原創(chuàng)或翻譯的精彩文章。本站的收錄代碼的標準是:簡單、精彩、通用。</p>  
  57. <br />  
  58. <textarea rows="8" cols="80" id="tempText">在編程的過程中,我們通常都會積累很多簡單、有效并且可重用的小段代碼,一個簡單的字符串 處理函數(shù)或者一個驗證郵件地址的正則表達式,又或者一個簡單的文件上傳類,甚至一個效果不錯的CSS導航樣式。</textarea>  
  59. <br /><br />  
  60. <input type="button" value="獲取選中的內(nèi)容" id="getSelectedText" />  
  61. <input type="button" value="FireFox 下獲取文本框里選中的內(nèi)容" id="getTextFieldSelection" />  
  62. <br />  
  63. <!--************************************* 實例代碼結(jié) 束 *************************************-->  
  64. </div>  
  65. </div>  
  66. <br />  
  67. </body>  
  68. </html>  
  • text.rar (1.9 KB)
  • 下載次數(shù): 6
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
HTML經(jīng)典試題
HTML5 Web存儲的localStorage和sessionStorage的使用方法【圖文說明】
ASP編程入門進階之二:認識表單
一句話插入木馬
幾款雙功能免殺超強版asp小馬
如何創(chuàng)建一個iPhone Web應(yīng)用
更多類似文章 >>
生活服務(wù)
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服