I have an input that is empty after page load, and if a user suddenly fill a value on it the value of the two inputs on the if condition should change to.
我在页面加载后输入为空,如果用户突然在其上填充值,则if条件上的两个输入的值应更改为。
My problem is when I fill an input, the if condition result doesn't changed in real time.
我的问题是当我填写输入时,if条件结果不会实时更改。
script:
脚本:
$(document).ready(function(){
var countTimerEmailName = setInterval(
function ()
{
emailName();
}, 500);
function emailName(){
if($('#emailCodeResult').val() != '' || $('#email').val() == ''){
clearInterval(countTimerEmailName);
}
$.ajax({
url:"view.php",
type:"GET",
data: { term : $('#email').val() },
dataType:"JSON",
success: function(result) {
}
});
};
});
2 个解决方案
#1
3
Fire your function on change
在改变时解雇你的职能
$('#inputA, #inputB').change(function(){
if($('#inputA').val() != '' || $('#inputB').val() == '') {
alert("True");
}else{
alert("False");
}
})
#2
1
You can use keyup
like this:
你可以像这样使用keyup:
$('#textboxID').on( 'keyup', function () {
//write your code here
});
For touch devices as rzr siad keyup won't occur. You can write a function that is called every, say 1 sec or whatever, like this:
对于触摸设备,因为rzr siad keyup不会发生。您可以编写一个每隔1秒钟或者其他任何一个调用的函数,如下所示:
t1=window.setInterval(function(){foo()},1000);
function foo()
{
// write function definition here
}
or use blur
as others suggested, if the you want to check value only after the user is done with that textbox and moves to next field.
或者如其他人建议的那样使用模糊,如果您只想在用户完成该文本框并移动到下一个字段后才检查值。
#1
3
Fire your function on change
在改变时解雇你的职能
$('#inputA, #inputB').change(function(){
if($('#inputA').val() != '' || $('#inputB').val() == '') {
alert("True");
}else{
alert("False");
}
})
#2
1
You can use keyup
like this:
你可以像这样使用keyup:
$('#textboxID').on( 'keyup', function () {
//write your code here
});
For touch devices as rzr siad keyup won't occur. You can write a function that is called every, say 1 sec or whatever, like this:
对于触摸设备,因为rzr siad keyup不会发生。您可以编写一个每隔1秒钟或者其他任何一个调用的函数,如下所示:
t1=window.setInterval(function(){foo()},1000);
function foo()
{
// write function definition here
}
or use blur
as others suggested, if the you want to check value only after the user is done with that textbox and moves to next field.
或者如其他人建议的那样使用模糊,如果您只想在用户完成该文本框并移动到下一个字段后才检查值。