Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript在JSP中输入Null测试_Javascript_Jsp_Testing_Null - Fatal编程技术网

Javascript在JSP中输入Null测试

Javascript在JSP中输入Null测试,javascript,jsp,testing,null,Javascript,Jsp,Testing,Null,我目前正在尝试填写表单中的一些字段。我在做一个测试,如果extnReason和extnDt为null,我什么也不做。但出于某种原因,它不断地输入检查并用null加载我的字段,这是我不想要的 function preloadFields() { //these values are coming in as null var extnReason = '<%=extnReason%>'; var extnDt = '<%=extnDt%>'; //set Extensi

我目前正在尝试填写表单中的一些字段。我在做一个测试,如果
extnReason
extnDt
null
,我什么也不做。但出于某种原因,它不断地输入检查并用
null
加载我的字段,这是我不想要的

function preloadFields() {

//these values are coming in as null
var extnReason = '<%=extnReason%>';
var extnDt = '<%=extnDt%>';

//set Extension Date blank on load
$('#extnDt').val("");

alert("reason ++++ " + extnReason);
alert("extnDt ++++ " + extnDt);

//it is entering these tests but I don't want them to
if(extnReason != null || extnReason != "null"){ 
    console.log("entered reason");
    $('#extnReason').val(extnReason);
}

if(extnDt != null || extnDt != "null") {
    console.log("entered extnDt");
    $('#extnDt').val(extnDt);
}

}
函数预加载字段(){
//这些值以null形式输入
var extnReason='';
var extnDt='';
//加载时将扩展日期设置为空
$('#extnDt').val(“”);
警报(“原因+++”+extnReason);
警报(“extnDt++++”+extnDt);
//它正在进入这些测试,但我不想让它们进入
如果(extnReason!=null | | extnReason!=“null”){
控制台日志(“输入原因”);
$('#extnReason').val(extnReason);
}
如果(extnDt!=null | | extnDt!=“null”){
控制台日志(“输入extnDt”);
$('#extnDt').val(extnDt);
}
}
任何帮助都将不胜感激

您需要

if(extnReason != null && extnReason != "null")
而不是

if(extnReason != null || extnReason != "null")
因为如果
extnReason
'null'
第一个条件
'null'!=null
将返回
true
,因此OR检查将计算为
true
,因此输入设置值的代码块

如果条件相同,则另一个条件相同

预加载字段的另一种方法:您也可以只设置输入标记的
属性,而不使用
预加载字段
?i、 e.类似于:

 <input type="text" id="extnDt" value="${extnDt != null ? extnDt : ''}" />


感谢您的快速回复!出于某种原因,我认为
|
会声明其中一个必须为true才能进入操作,
&&
意味着两者都必须为true才能进入操作。我的代码不允许您以其他方式执行此操作。非常感谢您的帮助。没问题,只是想澄清一下:
&&
是和:两个条件都必须为真,
|
是,或者,只有一个条件必须为真。我明白了。为什么在这种情况下它既是
null
又是
“null”
?这让我感到奇怪,因为它表明两者都是真实存在的。我被引导去相信
null
意味着没有任何值,
“null”
是一个
字符串
。没错,当你使用
|
时,你会问你的字符串是不是
null
(没有值)还是不是
'null'
(即字符串)。由于字符串
'null'
不是无值,if条件的第一部分为
true
,因此整个if为true,并输入分支。这有意义吗?