,大家好,
如果用户名文本框为空,或者密码文本框为空,并且代码如下,则可以显示警告消息。
我想显示图片警告,而不是显示警告消息
如何在下面的代码中制作它?
<input type="text" id="UsernameTextBox" name="UsernameTextBox"/>
<input type="text" id="PasswordTextBox" name="PasswordTextBox"/>
<input type="button" onclick="LoginButonOnclick()" value="Enter"/>
function LoginButonOnclick() {
var data= {
Username: $('#UsernameTextBox').val(),
Password: $('#PasswordTextBox').val(),
};
if (data.Username==null) {
alert(UserName Can Not Be Empty!"); // I want to show image warning
}
if (data.Password==null) {
alert("Password Can Not Be Empty!"); // I want to show image warning
}
if (data.Username&& data.Password) {
$.ajax({
url: "/Home/Menu",
type: "POST",
dataType: "json",
contentType: 'application/json',
data: JSON.stringify(data),
success: function (mydata) {
if (mydata.error == true) {
// İnvalid
}
else {
// Success
}
},
error: function () {
$("#message").html("Error ");
}
});
return false;
}
}
答案 0 :(得分:0)
您可以将img附加到html元素。
if (data.Username==null) {
$("#alert-img-place").html('<img src="img1.png">'); // Change to path to your img
}
if (data.Password==null) {
$("#alert-img-place").html('<img src="img2.png">'); // Change to path to your img
}