Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript如何在悬停到图像上显示消息_Javascript_Jquery_Image_Hover_Mouse - Fatal编程技术网

Javascript如何在悬停到图像上显示消息

Javascript如何在悬停到图像上显示消息,javascript,jquery,image,hover,mouse,Javascript,Jquery,Image,Hover,Mouse,我可以用下面的代码显示图像警告。如果用户名或密码为空 我想显示消息,如果鼠标悬停在警告图像上 比如, 用户名为“用户名不能为空!”,密码为“密码不能为空!” 在何处编辑鼠标悬停到图像上显示消息 我的Javascript代码: function LoginButonOnclick() { var data= { UserName: $('#UserNameTextBox').val(), Password: $('#PasswordTextBox').val(), }; if

我可以用下面的代码显示图像警告。如果用户名或密码为空

我想显示消息,如果鼠标悬停在警告图像上

比如,

用户名为“用户名不能为空!”,密码为“密码不能为空!”

在何处编辑鼠标悬停到图像上显示消息

我的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" />');
  }
}
函数loginbutonclick(){
风险值数据={
用户名:$('#UserNameTextBox').val(),
密码:$('#PasswordTextBox').val(),
};
if(data.UserName==null){
$(“#showwarning1”).html(“”);
}
if(data.Password==null){
$(“#showwarning2”).html(“”);
}
}
我的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>

通过使用jquery,您可以非常轻松地完成这项工作


使用jquery可以非常轻松地完成这项工作


可以考虑使用jQuyYi工具提示控件。

参考:


可选地使用悬停事件:

您可以考虑使用jQuyYi工具提示控件。

参考:


或者使用悬停事件:

为什么要自己去把事情复杂化。。。。它是如此简单。。。 使用
为什么要自己去把事情复杂化。。。。它是如此简单。。。 使用
您可以使用onmouseover属性调用相同的函数,以便它在悬停时执行与单击时相同的操作

<img src="~/Image/warning.png" title="Password is empty!!"/>
函数loginbutonclick(){
风险值数据={
用户名:$('#UserNameTextBox').val(),
密码:$('#PasswordTextBox').val(),
};
if(data.UserName==null){
$(“#showwarning1”).html(“”);
}
if(data.Password==null){
$(“#showwarning2”).html(“”);
}
}

或者,您也可以使用jQuery

您可以使用onmouseover属性调用相同的函数,以便它在悬停时执行与单击时相同的操作

<img src="~/Image/warning.png" title="Password is empty!!"/>
函数loginbutonclick(){
风险值数据={
用户名:$('#UserNameTextBox').val(),
密码:$('#PasswordTextBox').val(),
};
if(data.UserName==null){
$(“#showwarning1”).html(“”);
}
if(data.Password==null){
$(“#showwarning2”).html(“”);
}
}

或者,您也可以使用jQuery

为什么有人会用其他方式来处理一张小纸条?为什么有人会用其他方式来处理一张小纸条?
  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" />');
  }
}
<input type="text" id="UsernameTextBox" name="UsernameTextBox"/>
    <input type="text" id="PasswordTextBox" name="PasswordTextBox"/>
    <input type="button" onclick="LoginButonOnclick()" onmouseover="LoginButonOnclick()" value="Enter"/>

    <div id="showwarning1"></div>
    <div id="showwarning2"></div>