2鼠标移动到热点上,显示详细信息
<html>
<head>
<scripttype="text/javascript">
functionshowOne(id){
var xhr =window.XMLHttpRequest?new XMLHttpRequest():newActiveXObject("Msxm12.XMLHTTP");
varurl="index.php?c=user&a=showOne";
xhr.open("post",url,true);//post方式打开地址栏必须传一个头文件
//true 参数表示是否异步
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send("brand_id="+id);
xhr.onreadystatechange =callback;
function callback(){
//alert(xhr.readyState);
if(xhr.readyState ==4){
if(xhr.status== 200){//请求发送成功
//eval()如果想要将字9符串转化成对象,需先将对象运行一下,通过'()'
varjson =eval("("+xhr.responseText+")");
varnew_div =document.createElement('div');
new_div.style.backgroundColor= "yellow";
new_div.id="new_div";
new_div.style.position="absolute";
new_div.style.width="250px";
new_div.style.marginLeft="180px";
new_div.innerHTML="详细信息:<br/>网址:"+json.brand_wz+"<br/>简介:"+json.brand_intro;
document.getElementById(id).appendChild(new_div);
}
}
}
}
functiondelOne(id){
var new_div=document.getElementById("new_div");
document.getElementById(id).removeChild(new_div);
}
</script>
</head>
<body>
<tablewidth="250px" align="center">
<caption>地图式图层浮动</caption>
<{foreachfrom=$list item="value"}>
<trbgcolor="#ccc">
<tdid="<{$value.brand_id}>"οnmοuseοver="showOne(<{$value.brand_id}>)"οnmοuseοut="delOne(<{$value.brand_id}>)"><{$value.brand_id}></td>
<tdid="<{$value.brand_id}>"οnmοuseοver="showOne(<{$value.brand_id}>)"οnmοuseοut="delOne(<{$value.brand_id}>)"><{$value.brand_name}></td>
</tr>
<{/foreach}>
</table>
</body>
</html>
// 命令模型层查询数据 视图层显示
//实现 地图搜索 弹出图层
public function showDetailAction(){
$user_model=newuserModel('localhost','root','','yanhua');
$rows=$user_model->getAll();
$this->smarty->assign('list',$rows);
$this->smarty->display('showDetail.tpl');
}
// 获取传递得值 在模型层查询 并返回
public function showOneAction(){
$brand_id=$_REQUEST['brand_id'];
$user_model=newuserModel('localhost','root','','yanhua');
$rows=$user_model->getOne($brand_id);
echo json_encode($rows);
}
userController.class.php//控制器代码
// 命令模型层查询数据 视图层显示
//实现 地图搜索 弹出图层
publicfunction showDetailAction(){
$user_model=newuserModel('localhost','root','','yanhua');
$rows=$user_model->getAll();
$this->smarty->assign('list',$rows);
$this->smarty->display('showDetail.tpl');
}
// 获取传递得值 在模型层查询 并返回
publicfunction showOneAction(){
$brand_id=$_REQUEST['brand_id'];
$user_model=newuserModel('localhost','root','','yanhua');
$rows=$user_model->getOne($brand_id);
echojson_encode($rows);
}
userModel.class.php //模型层查询数据
public function getAll(){
$sql= "select * from brand";
$res=mysql_query($sql);
$rows=array();
while($row=mysql_fetch_assoc($res)){
$rows[]=$row;
}
return$rows;
}
publicfunction getOne($brand_id){
$sql= "select * from brand where brand_id='".$brand_id."'";
$res=mysql_query($sql);
$row=mysql_fetch_assoc($res);
return$row;
}