简体   繁体   中英

Javascript Notification Pop-up?

Looking for the best approach to perform a javascript notification pop-up if amount in field A is edited to a smaller amount that what is found in field B?

We aren't using any js frameworks but that option isn't ruled out.

Thanks.

您可以尝试使用alert功能。

You can use alert function

if(valueOfFieldA < valueOfFieldB)
{
    alert('please enter amount greater than Field B');
}

I would recommend jQuery then you could do:

   <input id='fld1' type=text value=5>
   <div id="label1" style="display:none;">&nbsp;</div>
   <input id='fld2' type=text value=5>

and in your script

 $(document).ready(function() {
            $('#fld1').change(function(){
                if($(this).val()>$('#fld2').val()){
                  //display it on the form
                  $('#label1').append('Fld 1 cannot be bigger than fld2!').show();
                  //or alert it to the user using alert();
                   alert('Fld 1 cannot be bigger than fld2!');
                }
            })
        });

see http://api.fatherstorm.com/test/4168233.php

I guess this is what you were looking for.

Code rewritten here for your convenience

HTML

<label>A</label><input type="text" id="input1" onblur="checkBValue()"/><br/>
<label>B</label><input type="text" id="input2"/>

JS

function checkBValue(){

    var b=parseInt(document.getElementById("input2").value);
    var a=parseInt(document.getElementById("input1").value);
    if (a<b && !isNaN(a) && !isNaN(b)) alert("A="+a+ " is less than B="+b);
    return;
}

无耻的插件,但这是我编写的用于非常轻松地处理通知的库: http : //shaundon.github.io/simple-notifications/

简单地,您可以创建一个js函数并使用A输入的onchange事件调用它,因此您可以指定通知用户的特殊方式;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM