JSは、次のようにマウスによって選択されたテキストコードを取得します。
<html> <head> <head> <Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/> <title> jsマウスで選択されたテキストを取得</title> <スクリプト言語= "javascript"> <! - try {try selecttext(){var var selecter = window.getSelection(); if(selecter!= null && selecter.trim()!= ""){alert(selecter);}} catch(err){var selection = document.selection.createrange(); var s = selecter.text; if(s!= null && s.trim()!= ""){alert(s)}}} string.prototype.trim = function(){return this.replace(/(^/s*)|(/s*$)/g、g、g、 ");} //-川は奇妙に死に、下流の住民は頻繁に奇妙な病気に苦しみ、海岸沿いの植物は絶えず変異します。それらは残留農薬ですか?または生化学的攻撃?今夜のCCTV-10「科学探査」に注意してください。今後の特別プログラム:「川沿いの神秘的な足の洗濯マン - 中毒者フットボールチーム」</span> </body> </html>JSは、マウスの選択された値を取得します
if(window.getSelection){//一般的なブラウザーuserselection = window.getSelection();} else if(document.selection){// ie browser、opera userselection = document.selection.createrange();} userselection.tostring();上記は、編集者によって導入されたJSマウスによって選択されたテキストです。私はそれが誰にでも役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は、すべての人に時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!