我想首先说我不懂Java Script。我在一家旅行社工作,从事内容创作和工作。设计。我在Eclipse中使用Sabre Scribe完成了一些小的脚本工作。如果人们有关于去哪里学习基础知识的建议,那就太好了。 编辑:这是使用程序Adobe Captivate执行Javascript函数。
无论如何,我现在的目标是将按键改为符号。我需要把“'”变成“‡”。我非常乐意花时间学习和研究这个,但我所做的所有研究都没有让我更接近找到解决方案。但是,我已经学习了如何在按下该键时创建警报,我似乎无法使用该键来键入不同的键。
长话短说,我会很感激这方面的一些资源或帮助。
答案 0 :(得分:1)
您需要在输入onkeyup
上进行搜索和替换(使用正则表达式)。然后,您可以使用散列替换适当的值,并将值替换回输入。
这是我一周前写的一些代码:
// note: this needs to be escaped *here*
const hotSwapVals = {
':music:': '♫',
':rocket:': '',
':sat:': '',
':satellite:': ''
};
// swap out text with emoji on an input
function hotSwap(obj) {
if(obj.constructor !== HTMLInputElement)
throw 'Object must be HTMLInputElement';
// must be escaped prior, otherwise errors will occur
const regex = new RegExp(Object.keys(hotSwapVals).join('|'), 'g');
const val = obj.value.replace(regex, key => hotSwapVals[key]);
if(obj.value != val) // prevents moving cursor to end if not needed
obj.value = val;
}
然后通过将输入对象作为参数传递,将其绑定到对象。
答案 1 :(得分:1)
此代码将更改'按键时符号的字符...
<!doctype html>
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</head>
<body>
<input id="textField" type="text"></input>
<script>
jQuery(document).ready(function($) {
$('#textField').on('keydown', function(e) {
//console.log(e.keyCode); // Will tell you the code for the key pressed.
if (e.keyCode == 222) {
e.target.value += '‡'; // Add the symbol
e.preventDefault(); // Stop the single quote from being added.
}
});
});
</script>
</body>
</html>
答案 2 :(得分:1)
Adobe Captivate似乎有自己独特的Javascript风格。在阅读了common-js-interface页面后,这样的东西可能会起作用 - 你可以尝试它作为测试(我没有程序)??
window.cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED", function(e) {
var value = window.cpAPIInterface.getVariableValue("myTextBox");
value += 'testing';
window.cpAPIInterface.setVariableValue('myTextBox', value);
}, 'myTextBox');
当然将所有地方改为'myTextBox'到文本字段变量的名称。
如果这样可行,那么我可能会想出一些代码来改变'到那个符号。