Javascript图像警告不起作用

use*_*307 2 javascript warnings image

如果用户名或密码为空,我会尝试显示图像警告消息.

但是,如果我的用户名或密码为空,则不会显示图像.我想念的地方?

我的Javascript代码

function LoginButonOnclick() {
var data= {
UserName: $('#UserNameTextBox').val(),
Password: $('#PasswordTextBox').val(),
};
if (data.UserName== null) {
$("#showwarning").html('<img src="~/Image/warning.png">');
}
if (data.Password== null) {
$("#showwarning").html('<img src="~/Image/warning.png" />');
}
}
Run Code Online (Sandbox Code Playgroud)

我的Html代码:

<input type="text" id="UsernameTextBox" name="UsernameTextBox"/>
<input type="text" id="PasswordTextBox" name="PasswordTextBox"/>
<input type="button" onclick="LoginButonOnclick()" value="Enter"/>

<div id="showwarning"></div>
Run Code Online (Sandbox Code Playgroud)

小智 5

 data.UserName=="" //an empty string is not null
Run Code Online (Sandbox Code Playgroud)