以下是获得textarea中鼠标选中的文字的方法: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <mce:script type="text/javascript" language="javascript"><!-- function boldThis(from) { strSelection = document.selection.createRange().text alert(strSelection); if (strSelection == "") { return false; } else document.selection.createRange().text = "[b]" + strSelection + "[/b]" return; } // --></mce:script> </head> <body > <form name="form1" method="post" action=""> <textarea name="textarea" cols="50" rows="20">我选中"程序员大本营",点击图片按钮,自动在"程序员大本营"添加代码