LittleBill

JavaScript获取鼠标选择的文本内容

这里需要用到两个属性selectionStart与selectionEnd,且IE、Chrome、FF都支持此属性。

<textarea id="codeText" rows="10" cols="40"></textarea>
<button id="search">查找</button>
$('#search').click(function(){
	var codeText = $("#codeText")[0];
	codeText = codeText.value.slice(codeText.selectionStart,codeText.selectionEnd);
	alert(codeText);
});

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注