节点动态加onclick动作不管用,加onmouseover管用
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'autoinTest.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="xmlhttp.js"></script>
<style type="text/css">
/* 整个无序列表的样式 , 关键点如下:
position : 设置为绝对定位, 这样列表可以出现在屏幕的任意位置
width: 指定宽度,否则列表会满屏显示
list-style-image, list-style-type : 设置为null,去掉默认的列表符号
display : 初始状态设置为隐藏
z-index : 调高显示优先级
*/
ul.list {
position:absolute;
width: 130px;
border:solid 1px #aaa;
list-style-image:none;
list-style-type:none;
margin:0px;
padding:2px;
font-size:12px;
font-family:微软雅黑;
cursor:pointer;
display:none;
z-index:999;
background-color:#eee;
}
ul.list li {
padding:0px;
}
/*
每一个选项的样式 , 关键点如下:
display : 设置为block可以让背景色整行显示
text-decoration:去掉默认的下划线
zoom: 缩放属性,设置为1,避免在IE浏览器中出现不必要的换行
*/
/*
鼠标移动到选项上的样式, 修改了背景色
*/
ul.list li:hover {
display:block;
padding:2px;
background-color:#ccc;
color:#222;
zoom:1
}
</style>
<script type="text/javascript">
function autoin(o){
var xmlhttp=ajaxFunction();
xmlhttp.open("post","autoin");
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange=function(){
back1(xmlhttp);
};
xmlhttp.send("c="+o.value);
}
function back1(xmlhttp){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var list=document.getElementById("list");
var info=xmlhttp.responseXML;
info=info.getElementsByTagName("province");
while(list.firstChild!=null)
list.removeChild(list.firstChild);
for(var i=0;i<info.length;i++){
var li=document.createElement("li");
var a_txt=info[i].lastChild.firstChild.nodeValue;
li.appendChild(document.createTextNode(a_txt));
li.setAttribute("onmouseover","getOne(this)");//换onclick不管用
list.appendChild(li);
}
show();
}
}
function getOne(o){
var txt=o.firstChild.nodeValue;
var input=document.getElementById("input");
input.value=txt;
var ul=document.getElementById("list");
ul.style.display="none";
}
function show(){
var o=document.getElementById("input");
var ul=document.getElementById("list");
ul.style.left=o.offsetLeft;
ul.style.top=o.offsetTop+o.offsetHeight;
ul.style.width=o.offsetWidth;
ul.style.display="block";
}
function hide(){
var ul=document.getElementById("list");
ul.style.display="none";
}
</script>
</head>
<body>
This is my JSP page. <br>
<input id="input" type="text" onblur="hide()" onkeyup="autoin(this)"/>
<ul id="list" class="list">
</ul>
</body>
</html>
相关推荐
c# 在webFrom上实现tabcontrol功能(onmouseover事件,onclick事件)
c# 在webFrom上实现tabcontrol功能(onmouseover事件,onclick事件) 京华志&精华志出品 希望大家互相学习,互相进步 支持CSDN 支持微软 主要包括C# ASP.NET SQLDBA 源码 毕业设计 开题报告 答辩PPT等
js动态添加onclick事件可传参数与不传参数
本节主要介绍了js动态添加onclick事件可传参数与不传参数,需要的朋友可以参考下
js动态添加的DIV中的onclick事件简单实例
下面小编就为大家带来一篇js动态添加的DIV中的onclick事件简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
js修改onclick动作的四种方法(推荐)
第一种:button.onclick = Function(“alert(‘hello’);”); 第二种:button.onclick = function(){alert(“hello”); }; 第三种:button.onclick = myAlert; function myAlert(){ alert(“hello”); } 第四种: 这种情况更加动态,更为实用,而且还能添加多个函数(添加的事件的顺序即执行顺序),呵呵 if(window.addEventListener){ //
js ondocumentready onmouseover onclick onmouseout 样式
下面都是一些上面的事件触发的事先定义的代码。


