How does JS judge whether the text value of < td > is or not?

<td class="bz">  </bz>

js 

$(".bz").each(function(i,n){
    var obj = $(n);
    var val = obj.text();
    alert(val);
    if(val == "" || val == null || val == undefined){
        alert(val);
        wglx += "null,";
    }else{
        wglx += obj.text() + ",";
    }
        
});
< H2 > the problem now is when there is no content in td < / H2 >

if (val = =""| | val = = null | | val = = undefined)
this sentence has no effect
and if there is a value, alert will not be executed at all
cannot be judged

.
Oct.07,2021

Brother problem has been found. Look at the screenshot! See if it's your problem.


trim after taking out the value


upstairs is right. I'll test it for you. It's OK to have no spaces at first, but if you add spaces, there will be problems, so you can't pop up. Add trim:
can code: http://jsrun.net/N8hKp/edit

.
Menu