正在寻找类似于mircrosoft office autocorrect的jquery文本区域脚本
Looking for a jquery textarea script similar to mircrosoft office autocorrect
我正在寻找一个类似于microsoft office autocorrect的jquery/javscript文本区域脚本。使用Microsoft office,我可以编写<=并得到≤。与这些类似:
>= gives ≥
-> gives →
+- gives ±
(c) gives ©
(e) gives €
还有更多。是否存在一些jquery/javascript脚本来模拟文本区域输入字段的此功能?
编辑:谢谢你的回答!
我最近使用jquery进行了类似于MS office的自动更正
以下是演示:http://jsfiddle.net/73sEv/6/
function autoCorrect(searchString, replaceString) {
$("textarea").keyup(function(e) {
// escape some regex chars
var escapedString = searchString.replace( /([''.*+?|()'[']{}])/g, "''$1" );
// finds current cursor position
var pos = $(this).prop("selectionStart");
// this turns the textarea in a string
var text = $(this).val();
//only search for strings just typed
var stringToSearch = text.substring(pos-searchString.length,pos);
if (new RegExp(escapedString).test(stringToSearch) === true) {
//if there is a match put the replaceString in the right place
var newText = text.substring(0,pos-searchString.length) + replaceString + text.substring(pos);
$(this).val(newText);
//adjust the cursor position to the new text
var newpos = pos - searchString.length + replaceString.length;
this.setSelectionRange(newpos,newpos);
}
});
}
你可以自定义你想要的方式。例如:
autoCorrect("=>", '⇒');
autoCorrect("->", "→");
autoCorrect("+-", "±");
autoCorrect("<=", "≤");
autoCorrect(">=", "≥");
autoCorrect("(c)", "©");
autoCorrect("(e)", "€");
相关文章:
- jQuery文本属性中的Html代码
- JQuery文本区域字母表
- jquery文本输入框传递给变量
- jQuery文本解析器
- JQuery文本旋转器
- jQuery文本返回NULL
- 使用WP UI从选项卡到选项卡的Jquery文本链接
- 正在寻找类似于mircrosoft office autocorrect的jquery文本区域脚本
- JQuery文本编辑器-在工具栏中添加其他下拉列表
- jQuery文本未使用fadeIn正确显示
- jQuery文本区域计数器
- Jquery 文本区域未更新
- 在它们之间切换时,jQuery 文本显示在活动文本下方
- Jquery文本输入行为搞笑
- 在 jQuery 文本区域中编辑 Div 内容
- jQuery文本html操作,以查找大量文本中出现的字符,然后更改其颜色
- 需要 Jquery 文本动画自定义帮助
- Jquery 文本动画
- Jquery - 文本等于(邮件输入错误)
- 将 jquery 文本替换为 TM 字符实体,并用 jquery 替换