首页 > 解决方案 > 文本框中的自动热键

问题描述

我正在尝试使用简单的用户输入文本框创建一个网页,并且当输入某些组合时会产生特定的热键结果。

想象一下 Autohotkey,而不是在网页上运行的 PC 上运行。

例如,如果有人在用户文本框中输入“修复”,这将变为

  1. 做了x件事
  2. 在这里做了 x 另一件事
  3. 完成维修

(这只是一个例子)

这怎么能在一个网页上设置?

标签: javascripthtmlautohotkey

解决方案


找到如下解决方案

在第 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;
});
});

推荐阅读