gpt4 book ai didi

javascript - jQuery 虚拟键盘正在保存先前输入的值

转载 作者:行者123 更新时间:2023-12-02 23:33:52 25 4
gpt4 key购买 nike

我使用虚拟键盘,但遇到了问题。

问题是,在一个用户界面中,我有几个输入字段,对于每个字段,我都有类“输入”,它调用键盘。

当我点击第一个输入并输入数据时,先前输入字段的数据将复制到新的。

$(document).ready(function () {
$(".numpad").hide();
$('.input').click(function () {
$('.numpad').fadeToggle('fast');
});

$('.del').click(function () {
$('.input').val($('.input').val().substring(0, $('.input').val().length - 1));
});
$('.faq').click(function () {
alert("It's virtual keyboard");
})
$('.shuffle').click(function () {
$('.input').val($('.input').val() + $(this).text());
});

});

$(".input").on("click", function () {
$('.modal, .cover').removeClass("hidden");
$('.modal').addClass("zoom");
});

//hide modal
$(".cover, .close").on("click", function () {
$('.modal').attr('class', 'modal');
$('.modal, .cover').addClass("hidden");
});
.keyBoardButton {
margin: 13px;
}

.keyBoardButton {
display: inline-block;
border: 1px solid #fff;
color: #fff;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
font-family: Verdana;
width: auto;
height: auto;
font-size: 22px;
padding: 20px 27px;
background-color: #878787;
}

.keyBoardButton:hover, .keyBoardButton:active {
border: 1px solid #FFFFFF;
color: #000;
background-color: #fff;
}

.cover {
z-index: 1;
position: fixed;
height: 100%;
width: 100%;
background-color: #333;
top: 0;
left: 0;
opacity: .9;
}

.modal {
z-index: 2;
height: 390px;
width: 350px;
background-color: #262626;
border-radius: 5px;
text-align: center;
border-top: solid 3px #262626;
position: absolute;
opacity: 0.9;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}

.modal .content p {
font-size: 2em;
color: #fff;
height: 50px;
width: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}

.tiltup {
display: block;
transform: perspective(300px);
animation: tiltup 0.7s;
animation-fill-mode: forwards;
padding-top: 0;
}

@keyframes tiltup {
0% {
bottom: -400px;
opacity: 0;
transform: rotateX(-80deg);
border-top: solid 40px;
}

30% {
opacity: 0;
}

100% {
bottom: 0;
}
}

.zoom {
display: block;
animation: zoom 0.7s;
animation-fill-mode: forwards;
}

@keyframes zoom {
0% {
opacity: 0;
transform: scale(0, 0);
}

30% {
opacity: 0;
}

100% {
bottom: 0;
}
}

.hidden {
display: none;
}

.reverse {
animation-direction: reverse;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="input">
<input type="text" class="input">
<input type="text" class="input">
<input type="text" class="input">

<div class='cover hidden'></div>
<div class='modal hidden'>
<div class='content'>
<div class="numpad">
<div id="container">
<div>
<button class="shuffle keyBoardButton">1</button>
<button class="shuffle keyBoardButton">2</button>
<button class="shuffle keyBoardButton">3</button>
</div>
<div>
<button class="shuffle keyBoardButton">4</button>
<button class="shuffle keyBoardButton">5</button>
<button class="shuffle keyBoardButton">6</button>
</div>
<div>
<button class="shuffle keyBoardButton">7</button>
<button class="shuffle keyBoardButton">8</button>
<button class="shuffle keyBoardButton">9</button>
</div>
<div>
<button class="del keyBoardButton">X</button>
<button class="shuffle keyBoardButton">0</button>
<button class="faq keyBoardButton">?</button>
</div>
</div>
</div>
</div>

</div>

正如您所看到的,当点击输入字段时,虚拟键盘将在模式窗口中打开,添加数据后,在其他输入字段中该数据将复制。

因此,对于每个输入,我需要单独的数据。

最佳答案

看看这个片段,你就会得到一些想法。

$(document).ready(function () {

var selected_inp;
$(".numpad").hide();
$('.input').click(function () {
selected_inp = $(this);
$('.numpad').fadeToggle('fast');
});

$('.del').click(function () {
$('.input').val($('.input').val().substring(0, $('.input').val().length - 1));
});
$('.faq').click(function () {
alert("It's virtual keyboard");
})
$('.shuffle').click(function () {
//$('.input').val($('.input').val() + $(this).text());
selected_inp.val($(this).text());
});
(function ($) {

$.fn.shuffle = function () {

var allElems = this.get(),
getRandom = function (max) {
return Math.floor(Math.random() * max);
},
shuffled = $.map(allElems, function () {
var random = getRandom(allElems.length),
randEl = $(allElems[random]).clone(true)[0];
allElems.splice(random, 1);
return randEl;
});

this.each(function (i) {
$(this).replaceWith($(shuffled[i]));
});

return $(shuffled);

};

})(jQuery);

});

$(".input").on("click", function () {
$('.modal, .cover').removeClass("hidden");
$('.modal').addClass("zoom");
});

//hide modal
$(".cover, .close").on("click", function () {
$('.modal').attr('class', 'modal');
$('.modal, .cover').addClass("hidden");
});
.keyBoardButton {
margin: 13px;
}

.keyBoardButton {
display: inline-block;
border: 1px solid #fff;
color: #fff;
border-radius: 30px;
-webkit-border-radius: 30px;
-moz-border-radius: 30px;
font-family: Verdana;
width: auto;
height: auto;
font-size: 22px;
padding: 20px 27px;
background-color: #878787;
}

.keyBoardButton:hover, .keyBoardButton:active {
border: 1px solid #FFFFFF;
color: #000;
background-color: #fff;
}

.cover {
z-index: 1;
position: fixed;
height: 100%;
width: 100%;
background-color: #333;
top: 0;
left: 0;
opacity: .9;
}

.modal {
z-index: 2;
height: 390px;
width: 350px;
background-color: #262626;
border-radius: 5px;
text-align: center;
border-top: solid 3px #262626;
position: absolute;
opacity: 0.9;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}

.modal .content p {
font-size: 2em;
color: #fff;
height: 50px;
width: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}

.tiltup {
display: block;
transform: perspective(300px);
animation: tiltup 0.7s;
animation-fill-mode: forwards;
padding-top: 0;
}

@keyframes tiltup {
0% {
bottom: -400px;
opacity: 0;
transform: rotateX(-80deg);
border-top: solid 40px;
}

30% {
opacity: 0;
}

100% {
bottom: 0;
}
}

.zoom {
display: block;
animation: zoom 0.7s;
animation-fill-mode: forwards;
}

@keyframes zoom {
0% {
opacity: 0;
transform: scale(0, 0);
}

30% {
opacity: 0;
}

100% {
bottom: 0;
}
}

.hidden {
display: none;
}

.reverse {
animation-direction: reverse;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="input">
<input type="text" class="input">
<input type="text" class="input">
<input type="text" class="input">

<div class='cover hidden'></div>
<div class='modal hidden'>
<div class='content'>
<div class="numpad">
<div id="container">
<div>
<button class="shuffle keyBoardButton">1</button>
<button class="shuffle keyBoardButton">2</button>
<button class="shuffle keyBoardButton">3</button>
</div>
<div>
<button class="shuffle keyBoardButton">4</button>
<button class="shuffle keyBoardButton">5</button>
<button class="shuffle keyBoardButton">6</button>
</div>
<div>
<button class="shuffle keyBoardButton">7</button>
<button class="shuffle keyBoardButton">8</button>
<button class="shuffle keyBoardButton">9</button>
</div>
<div>
<button class="del keyBoardButton">X</button>
<button class="shuffle keyBoardButton">0</button>
<button class="faq keyBoardButton">?</button>
</div>
</div>
</div>
</div>

</div>

关于javascript - jQuery 虚拟键盘正在保存先前输入的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56372719/

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