2
자바 스크립트에서 조건부 문제가 있습니다. 논리에 따르면 답변은 false
이어야하며 콘솔에 따르면 진술은 false
이지만 실행하면 JavaScript는 사실이라고 말합니다.JavaScript는 실행시 true를 반환하지만 로직과 콘솔은 false라고 말합니다.
EDIT : 호출에 해당하는 HTML.
<div class="simblaEL form-group" data-drag="P935" id="P935">
<input type="text" class="form-control input-sm" name="x" id="x"
onblur="checkEmp();">
</div>
JS
는 예상대로 내가 콘솔document.getElementById('x').value === ''
에 넣어
//assume that the value of x is a string different from ''
if(document.getElementById('x').value === ''){
// do some things
}
else{
// do other things
}
, 그것은 false
반환합니다. 실행했을 때, true
처럼 // do some things
으로 점프하여 JavaScript가 처리합니다.
var s = document.getElementById('x').value;
if(s.isEmpty())
및
var s = document.getElementById('x').value;
if(s.equals(''))
을 시도,
if('' === document.getElementById('x').value)
을 시도했지만 아무도 일하지. 이 코드는 DOM이로드 된 후에 실행되므로 존재하지 않는 요소를 확인하려고하는 것과는 다릅니다.
===, 자바 스크립트의 일부 equals'하지 isEmpty'와'' – clearshot66
이 경우에 사용 ==를 사용하지 마십시오; 물론 그들은 일하지 않을 것입니다. 자바 스크립트와 자바 스크립트를 혼동하고 있습니까? – Xufox
질문을 편집하고 [mcve]를 제공하십시오. – Xufox