用户登录
用户注册

分享至

利用AJAX实现鼠标悬浮获取值的代码

  • 作者: 飞扬的青葱
  • 来源: 51数据库
  • 2021-08-21
客户端代码mouseover.php
复制代码 代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.51sjk.com/Upload/Articles/1/0/270/270310_20210708032629630.jpg">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>鼠标悬浮测试</title>
</head>
<script type="text/javascript" language="javascript">
var xmlhttp;
function createxmlhttprequest(){
if(window.activexobject){
xmlhttp = new activexobject("microsoft.xmlhttp");
}
else if(window.xmlhttprequest){
xmlhttp = new xmlhttprequest();
}
}
function sendrequest(t){
var id = t.id
createxmlhttprequest();
var url = "mouseover_check.php?page=" +t.id ;
xmlhttp.onreadystatechange = callback;
xmlhttp.open('get',url,true);
xmlhttp.send(null);
}
function callback(){
if(xmlhttp.readystate == 4){
if(xmlhttp.status == 200){
document.getelementbyid("show").innerhtml = xmlhttp.responsetext;
}
}
}

</script>
<body>
<p>
<input type="text" value="here" id="1" onmouseover="sendrequest(this)" />
</p>
<p><br/>
<input type="text" value="haha" id="2" onmouseover="sendrequest(this)" />
</div>
</p>
<p></p>
<span id="show"></span>
</body>
</html>

服务器端代码:
mouseover_check.php
复制代码 代码如下:

<?php
header("content-type:text/html;charset=utf-8");
header("cache-control:no-cache,must-revalidate");
$name = $_get['page'];
if($name == '1'){
echo "111";
}
else{
echo "222";
}
?>
软件
前端设计
程序设计
Java相关