gpt4 book ai didi

javascript - 在 javascript keyup 函数中包含 javascript 代码块

转载 作者:行者123 更新时间:2023-12-03 06:20:57 33 4
gpt4 key购买 nike

我想在 javascript 中包含一个 javascript 片段/代码,例如,如果我输入

apalak,该单词应该像片段/代码中那样替换自身。 (word_file.js) 我尝试链接代码片段 js 文件,但它不起作用,所以我复制了下面的代码。

$(document).ready(function(){

$("#ta_1").keyup(function(event) {

var text2 = $(this).val();

test();

$("#ta_2").val(text2);

})
});

/*
///word_file.js

function test()
{
text2 = text2.replace(/abıca/g, "aBıçaZZZ");
text2 = text2.replace(/abrık/g, "aBRQZZZ");
text2 = text2.replace(/apşak/g, "apşqZZZ");
text2 = text2.replace(/abbak/g, "aBBqZZZ");
text2 = text2.replace(/aparma/g, "apRmaZZZ");
text2 = text2.replace(/apalisına/g, "apLiSıNaZZZ");
text2 = text2.replace(/appak/g, "appqZZZ");
text2 = text2.replace(/aparmadutı/g, "apRmDuTıZZZ");
text2 = text2.replace(/apışık/g, "apışQZZZ");
text2 = text2.replace(/apışıklık/g, "apışQLQZZZ");
text2 = text2.replace(/apalak/g, "apLqZZZ");



}


*/
<!DOCTYPE html>
<html lang="en">
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</head>

<body>

<textarea id="ta_1" rows="5" cols="28" ></textarea>

<textarea id="ta_2" rows="5" cols="28"></textarea>

</body>
</html>

最佳答案

<textarea id="ta_1" rows="5" cols="28"></textarea>
<textarea id="ta_2" rows="5" cols="28"></textarea>

<script>
$("#ta_1").keyup(function(event) {

var text2 = $(this).val();

text2 = test(text2);

$("#ta_2").val(text2);
});

function test(text2)
{
text2 = text2.replace(/abica/g, "aBiçaZZZ");
text2 = text2.replace(/abrik/g, "aBRQZZZ");
text2 = text2.replace(/apsak/g, "apsqZZZ");
text2 = text2.replace(/abbak/g, "aBBqZZZ");
text2 = text2.replace(/aparma/g, "apRmaZZZ");
text2 = text2.replace(/apalisina/g, "apLiSiNaZZZ");
text2 = text2.replace(/appak/g, "appqZZZ");
text2 = text2.replace(/aparmaduti/g, "apRmDuTiZZZ");
text2 = text2.replace(/apisik/g, "apisQZZZ");
text2 = text2.replace(/apisiklik/g, "apisQLQZZZ");
text2 = text2.replace(/apalak/g, "apLqZZZ");

return text2;
}
</script>

关于javascript - 在 javascript keyup 函数中包含 javascript 代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38874595/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com