gpt4 book ai didi

javascript - 如何设置这些按钮 'id' 值以附加到文本区域中?

转载 作者:行者123 更新时间:2023-12-02 16:09:49 25 4
gpt4 key购买 nike

我得到了一个代码,其中包含与与其正常附加 key 不同的字母相关的翼字符,我正在尝试创建一个破译它们的程序。不幸的是,我无法弄清楚如何添加到文本区域,只能覆盖已有的字符,这对我来说没有多大帮助。

我是一个完全的初学者,尤其是 Jscript,所以我希望这是有道理的。有人可以帮忙吗?

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body>
<br>
<!-- PLCKFBGDHMOERJAQNXYIZVXSUT cypher alphabet-->
<input type="submit" style="font-family:'wingdings'" value="P" style="width:100%" id="A" />
<input type="submit" style="font-family:'wingdings'" value="L" style="width:100%" id="B" />
<input type="submit" style="font-family:'wingdings'" value="C" style="width:100%" id="C" />
<input type="submit" style="font-family:'wingdings'" value="K" style="width:100%" id="D" />
<input type="submit" style="font-family:'wingdings'" value="F" style="width:100%" id="E" />
<input type="submit" style="font-family:'wingdings'" value="B" style="width:100%" id="F" />
<input type="submit" style="font-family:'wingdings'" value="G" style="width:100%" id="G" />
<br>
<br>
<input type="submit" style="font-family:'wingdings'" value="D" style="width:100%" id="H" />
<input type="submit" style="font-family:'wingdings'" value="H" style="width:100%" id="I" />
<input type="submit" style="font-family:'wingdings'" value="M" style="width:100%" id="J" />
<input type="submit" style="font-family:'wingdings'" value="O" style="width:100%" id="K" />
<input type="submit" style="font-family:'wingdings'" value="E" style="width:100%" id="L" />
<input type="submit" style="font-family:'wingdings'" value="R" style="width:100%" id="M" />
<input type="submit" style="font-family:'wingdings'" value="J" style="width:100%" id="N" />
<br>
<br>
<!-- I'll add the rest later -->

<textarea id="txtarea" name="txtarea"></textarea>

<script>

// INDIVIDUAL LETTER INPUT CODES
$(document).ready(function(){
$("#A").click(function(){
$('#txtarea').html('A');
});
});

$(document).ready(function(){
$("#B").click(function(){
$('#txtarea').html('B');
});
});

$(document).ready(function(){
$("#C").click(function(){
$('#txtarea').html('C');
});
});
$(document).ready(function(){
$("#D").click(function(){
$('#txtarea').html('D');
});
});
$(document).ready(function(){
$("#E").click(function(){
$('#txtarea').html('E');
});
});
$(document).ready(function(){
$("#F").click(function(){
$('#txtarea').html('F');
});
});
$(document).ready(function(){
$("#G").click(function(){
$('#txtarea').html('G');
});
});
$(document).ready(function(){
$("#H").click(function(){
$('#txtarea').html('H');
});
});
$(document).ready(function(){
$("#I").click(function(){
$('#txtarea').html('I');
});
});
$(document).ready(function(){
$("#J").click(function(){
$('#txtarea').html('J');
});
});
$(document).ready(function(){
$("#K").click(function(){
$('#txtarea').html('K');
});
});
$(document).ready(function(){
$("#L").click(function(){
$('#txtarea').html('L');
});
});
$(document).ready(function(){
$("#M").click(function(){
$('#txtarea').html('M');
});
});
$(document).ready(function(){
$("#N").click(function(){
$('#txtarea').html('N');
});
});
</script>
<!-- Ill add the rest later -->
</body>

最佳答案

您可以使用事件委托(delegate)来大大简化您的代码。只需在所有输入周围添加一个 div 即可。

<div id="letters">
<input type="submit" style="font-family:'wingdings'" value="P" style="width:100%" id="A" />
<input type="submit" style="font-family:'wingdings'" value="L" style="width:100%" id="B" />
<!-- etc -->
</div>

那么你的 jQuery 将只需要一个事件。

$(document).ready(function(){
var txt=$('#txtarea');
$("#letters").on('click','input',function() {
txt.val(txt.val()+this.value);
});
});

我相信这就是你想要的。

您可以创建一个包含 style 属性的类,并将其应用到所有input

.letters {
font-family:'wingdings';
width:100%;
}

<input type="submit" class="letters" value="P"/>

我创建了一个fiddle这样您就可以看到它的实际效果。

关于javascript - 如何设置这些按钮 'id' 值以附加到文本区域中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30332618/

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