我可以使用以下代码显示图像警告。如果用户名或密码为空。
如果鼠标悬停在警告图像上,我想显示消息。
例如;
“用户名不能为空!”对于用户名和“密码不能为空!”密码。
在何处编辑以在鼠标悬停到图像时显示消息?
我的 Javascript 代码:
function LoginButonOnclick() {
var data= {
UserName: $('#UserNameTextBox').val(),
Password: $('#PasswordTextBox').val(),
};
if (data.UserName== null) {
$("#showwarning1").html('<img src="~/Image/warning.png">');
}
if (data.Password== null) {
$("#showwarning2").html('<img src="~/Image/warning.png" />');
}
}
我的 HTML 代码:
<input type="text" id="UsernameTextBox" name="UsernameTextBox"/>
<input type="text" id="PasswordTextBox" name="PasswordTextBox"/>
<input type="button" onclick="LoginButonOnclick()" value="Enter"/>
<div id="showwarning1"></div>
<div id="showwarning2"></div>
最佳答案
为什么要自己把事情复杂化......它是如此简单......
使用 <img>
的 title 属性显示鼠标悬停消息的标签!!
<img src="~/Image/warning.png" title="Password is empty!!"/>
关于Javascript 如何在悬停到图像时显示消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910145/