[英]Don't know how to code this jQuery
這有點難以解釋。 好的,所以我有這個文本輸入(“ textmoney”),您在其中輸入數字,它將給出一年的估計收入。因此,當一個人輸入其數字並點擊時,他們可以看到他們的答案。說他們想輸入另一個數字,以便他們將文本輸入中的所有數字都退格,直到沒有任何內容為止。基本上,我想擁有它,所以當數字不再位於文本輸入框中時,第一個數字的答案就消失了。抱歉,如果您不明白我要說的是什么,因為我真的不知道如何解釋。(例如:當您在google中輸入內容並決定輸入其他內容時,您將刪除輸入內容並搜索結果消失。)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$('#textmoney').keydown(function (e){
if(event.keyCode == 13){
moneyFunction();
}})
$(document).keydown(function (e) {
if(event.keyCode == 82) {
reloadFunction();
}})
$(document).ready(function() {
$('#textmoney').keydown(function() {
$('#redotext').css('visibility', 'visible');
})})
$('#textmoney').mouseover(function() {
$('#textmoney').css('border', '1px solid black');
$('#textmoney').mouseout(function() {
$('#textmoney').css('border', '1px solid grey');
})})
</script>
<script>
function moneyFunction() {
var money = document.getElementById('textmoney').value;
var dailyE = money/365;
document.getElementById('demo').innerHTML = ("$" + dailyE + " " + "per day");
if ( document.getElementById('textmoney').value == 0) {
document.getElementById('demo').innerHTML = "You aint enter no chang";
}
} //Function tag
function reloadFunction() {
location.reload();
}
</script>
這是我將對此重新排序的方式,以滿足您的要求,並使它更易於閱讀。
$(document).ready(function() {
var $demo = $('#demo');
var $textMoney = $('#textmoney')
.keyup(function(e) {
if (e.keyCode === 13) {
var money = $(this).val();
if (isNaN(money) || money === '') {
$demo.text('You ainy enter no chang');
} else {
var dailyE = $(this).val() / 365;
$demo.text('$' + dailyE + ' per day');
}
} else if ($(this).val() === '') {
$demo.text('');
}
}).mouseover(function() {
$(this).css('border', '1px solid black');
}).mouseout(function() {
$(this).css('border', '1px solid grey');
});
});
JSFiddle: https ://jsfiddle.net/ws6cosh4/1/
我想我明白你的意思。 是這樣嗎
$("#textmoney").on('input',function () {
$("#answer").hide();
});
無論是否為空,在文本框輸入事件上都非常簡單。 如果為空,則刪除數據。
$("#textbox").on('input',function() {
if(("#textbox").val().length() == 0){
//your code goes here.
}
});
var textbox = document.getElementById("textbox")
textbox.addEventListener('input', function(event) {
event.preventDefault();
if (!!textbox.length) {
//enter code here
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.