简体   繁体   English

不知道如何编码这个jQuery

[英]Don't know how to code this jQuery

This is kinda hard to explain. 这有点难以解释。 Ok so i have this text input ("textmoney') that you enter a number into it and it will give the estimated amount of money made a year. So when a person types in their number and hits enter they can see their answer. Lets say that they want to enter another number so they backspace all the numbers in the text input until nothing is there. Basically i want to have it so when the numbers are no longer in the text input box the answer to their first number disappears. Im sorry if you don't understand what I'm trying to say because i really don't know how to explain this. (ex: When you type something into google and decide to type in something else you delete what you typed in and the search results disappear.) 好的,所以我有这个文本输入(“ 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>

Here's how I would reorder this a bit to meet your requirements and make it a little easier to read. 这是我将对此重新排序的方式,以满足您的要求,并使它更易于阅读。

$(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/ JSFiddle: https ://jsfiddle.net/ws6cosh4/1/

I think I know what you mean. 我想我明白你的意思。 Is it something like this? 是这样吗

http://jsfiddle.net/m8oef0ju/ http://jsfiddle.net/m8oef0ju/

$("#textmoney").on('input',function () {
    $("#answer").hide();
});

Simple on textbox input event chaeck whether it's empty or not. 无论是否为空,在文本框输入事件上都非常简单。 If it's empty then remove data. 如果为空,则删除数据。

$("#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.

相关问题 JQuery Quickfix:我不知道如何调用它 - JQuery Quickfix : I don't know how to call it 不知道如何在我的代码中将栅格应用于每个行星 - Don't know how to apply raster to every planet in my code 不知道如何在代码中使用 target=&quot;_blank&quot; - Don't know how to use target="_blank" in code jQuery验证不起作用不知道为什么 - jquery validation is not working don't know why 我确实知道如何解决语言/音频问题,但是我不知道如何将其作为代码组合在一起 - I do know how to solve the language/audio issue, but I don't know how to put it together as code jQuery:小绑定/悬停代码片段,几行长,不知道出了什么问题 - Jquery: Small bind hover/unbind snippet of code, few lines long, don't know what's wrong 元素在我的代码中不会.fadeTo。 不知道怎么了JavaScript,JQuery,HTML - elements wont .fadeTo in my code. Don't know what's wrong JavaScript, JQuery, HTML 我想重复代码,但不知道如何使用循环 - I want to repeat code but don't know how t use loops 我正在设置一个来自jQuery的href mailto,但我不知道如何设置目标_blank - I'm setting a href mailto from jQuery, but I don't know how to set the target _blank 我不知道如何在Angular2中包含js文件并使用jQuery - I don't know how to include js file and use jquery in angular2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM