javascript - 文本框中的自动热键
问题描述
我正在尝试使用简单的用户输入文本框创建一个网页,并且当输入某些组合时会产生特定的热键结果。
想象一下 Autohotkey,而不是在网页上运行的 PC 上运行。
例如,如果有人在用户文本框中输入“修复”,这将变为
- 做了x件事
- 在这里做了 x 另一件事
- 完成维修
(这只是一个例子)
这怎么能在一个网页上设置?
解决方案
找到如下解决方案
在第 3 行和第 4 行中,替换hotkeyhere
为您输入时想要替换的内容
在它说的地方Textreplace here
用你想要的文本替换它
$(document).keypress(function() {
var textarea=$('#txt');
textarea.val(textarea.val().replace(/hotkeyhere/g,"Textreplace here"));
textarea.val(textarea.val().replace(/hotkeyhere/g,"Textreplace here"));
});
$(document).ready(function(){
$('#copy').on('click', function(){
clipBoardValue = '';
$('#myForm').find('.input').each(function(){
if($(this).attr('type')== 'radio' ){
if($(this).is(':checked')){
clipBoardValue = clipBoardValue + ' ' + $(this).val();
}
}else{
clipBoardValue = clipBoardValue + ' ' +$(this).val();
}
});
console.log(clipBoardValue+ ' copied to clipboard');
copyToClipboard(clipBoardValue);
return false;
});
});
推荐阅读
- javascript - Angular 类不是 Angular 模块
- d3.js - 如何阻止 d3 工具提示离开页面?
- linux - 在没有父终止的情况下处理和传播 SIGHUP 信号到子进程
- python - 如何提取 zip 文件夹并查找特定文件名 Python 2
- sql - 仅在值匹配时识别
- javascript - 捆绑 React-native android 版本不接受代码更改
- php - 通过 json 请求的 Chartjs 数据未填充
- perl - 在命令行选项有条件地在 perl 中将默认编码设置为 utf-8
- node.js - 会话令牌未存储且无法从浏览器查看
- python - 如何绘制恒定长度的贝塞尔曲线?