扩展jQuery高亮网页中的文本选中
<script type="text/javascript">
//1。扩展jQuery
$.fn.selectRange = function (start, end) {
var curObj = $(this).get(0);
if (!curObj) return;
else if (curObj.setSelectionRange) {
curObj.focus(); curObj.setSelectionRange(start, end);
} /* WebKit */
else if (curObj.createTextRange) {
var range = curObj.createTextRange();
range.collapse(true);
range.moveEnd('character', end);
range.moveStart('character', start);
range.select();
} /* IE */
else if (curObj.selectionStart) {
curObj.selectionStart = start;
curObj.selectionEnd = end;
}
};
</script>
<script type="text/javascript">
$(function () {
//发送按钮注册一个鼠标悬浮事件
$('#sendBox :button.sendBtn').mouseover(function () {
$(this).css('backgroundPosition', '0 -195px');
}).mouseout(function () {
$(this).css('backgroundPosition', '-117px -165px');
});
//为“话题”超链接注册单击事件
$('#shareBox a.creatNew').click(function () {
if ($('#msgTxt').val().length == 0) {
$('#msgTxt').val('#输入话题标题#').selectRange(1, 7);
}
});