js文件中JavaScript句柄问题
运行不了啊,跟浏览器有关吗???哪位高手看看啊,代码如下:<html><head><title>导航树例子</title><scriptlanguage="javascr...
运行不了啊,跟浏览器有关吗???哪位高手看看啊,代码如下:
<html>
<head><title>导航树例子</title>
<script language="javascript" type="text/javascript" >
function dashu(e){
if(!document.getElementById) return;
if(!e) var e=window.event;
whicklink=(e.target)?e.target.id:e.srcElement.id;
menu=document.getElementById(whicklink+"menu");
boolean=(menu.style.display=="none");
obj=document.getElementById(whicklink);
objname=obj.firstChild.nodeValue.substring(3);
if(boolean){
menu.style.display=block;
obj.firstChild.nodeValue="[-]"+objname;
}
else{
menu.style.display=none;
obj.firstChild.nodeValue="[+]"+objname;
}
}
function cheshi(){
document.write("wodeshijiebushimeng");
}
document.getElementById("yonghu").onclick=dashu;
document.getElementById("bumen").onclick=dashu;
document.getElementById("xinxi").onclick=dashu;
document.getElementById("mybutton".onclick=cheshi;
</script>
</head>
<body>
<ul>
<li><a id="yonghu" href="#">[+]用户管理</a> <!--主菜单-->
<ul id="yonghumenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="bumen" href="#">[+]部门管理</a>
<ul id="bumenmenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="xinxi" href="#">[+]信息管理</a>
<ul id="xinximenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
</ul>
<form name="myform">
<input type="button" name="mybutton" id="mybutton" >
</form>
</body>
</html>
回一楼:还是不行,,给答案的先运行一下再说呀,,,我的目的是 导航树 ,点击会有动态的效果。。。。 展开
<html>
<head><title>导航树例子</title>
<script language="javascript" type="text/javascript" >
function dashu(e){
if(!document.getElementById) return;
if(!e) var e=window.event;
whicklink=(e.target)?e.target.id:e.srcElement.id;
menu=document.getElementById(whicklink+"menu");
boolean=(menu.style.display=="none");
obj=document.getElementById(whicklink);
objname=obj.firstChild.nodeValue.substring(3);
if(boolean){
menu.style.display=block;
obj.firstChild.nodeValue="[-]"+objname;
}
else{
menu.style.display=none;
obj.firstChild.nodeValue="[+]"+objname;
}
}
function cheshi(){
document.write("wodeshijiebushimeng");
}
document.getElementById("yonghu").onclick=dashu;
document.getElementById("bumen").onclick=dashu;
document.getElementById("xinxi").onclick=dashu;
document.getElementById("mybutton".onclick=cheshi;
</script>
</head>
<body>
<ul>
<li><a id="yonghu" href="#">[+]用户管理</a> <!--主菜单-->
<ul id="yonghumenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="bumen" href="#">[+]部门管理</a>
<ul id="bumenmenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="xinxi" href="#">[+]信息管理</a>
<ul id="xinximenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
</ul>
<form name="myform">
<input type="button" name="mybutton" id="mybutton" >
</form>
</body>
</html>
回一楼:还是不行,,给答案的先运行一下再说呀,,,我的目的是 导航树 ,点击会有动态的效果。。。。 展开
3个回答
展开全部
经过测试,可行!
下面是改好的代码!
<html>
<head><title>导航树例子</title>
<script language="javascript" type="text/javascript" >
function dashu(e){
if(!document.getElementById) return;
if(!e) var e=window.event;
whicklink=(e.target)?e.target.id:e.srcElement.id;
menu=document.getElementById(whicklink+"menu");
boolean=(menu.style.display=="none");
obj=document.getElementById(whicklink);
objname=obj.firstChild.nodeValue.substring(3);
if(boolean){
menu.style.display="block";
obj.firstChild.nodeValue="[-]"+objname;
}
else{
menu.style.display="none";
obj.firstChild.nodeValue="[+]"+objname;
}
}
function cheshi(){
document.write("wodeshijiebushimeng");
}
</script>
</head>
<body>
<ul>
<li><a id="yonghu" href="#">[+]用户管理</a> <!--主菜单-->
<ul id="yonghumenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="bumen" href="#">[+]部门管理</a>
<ul id="bumenmenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="xinxi" href="#">[+]信息管理</a>
<ul id="xinximenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
</ul>
<form name="myform">
<input type="button" name="mybutton" id="mybutton" >
</form>
</body>
</html>
<script>
document.getElementById("yonghu").onclick=dashu;
document.getElementById("bumen").onclick=dashu;
document.getElementById("xinxi").onclick=dashu;
document.getElementById("mybutton").onclick=cheshi;
</script>
下面是改好的代码!
<html>
<head><title>导航树例子</title>
<script language="javascript" type="text/javascript" >
function dashu(e){
if(!document.getElementById) return;
if(!e) var e=window.event;
whicklink=(e.target)?e.target.id:e.srcElement.id;
menu=document.getElementById(whicklink+"menu");
boolean=(menu.style.display=="none");
obj=document.getElementById(whicklink);
objname=obj.firstChild.nodeValue.substring(3);
if(boolean){
menu.style.display="block";
obj.firstChild.nodeValue="[-]"+objname;
}
else{
menu.style.display="none";
obj.firstChild.nodeValue="[+]"+objname;
}
}
function cheshi(){
document.write("wodeshijiebushimeng");
}
</script>
</head>
<body>
<ul>
<li><a id="yonghu" href="#">[+]用户管理</a> <!--主菜单-->
<ul id="yonghumenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="bumen" href="#">[+]部门管理</a>
<ul id="bumenmenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
<li><a id="xinxi" href="#">[+]信息管理</a>
<ul id="xinximenu"><li><a href="#">修改密码</a></li>
<li><a href="#">注销账号</a></li>
<li><a href="#">查看密码</a></li>
</ul>
</li>
</ul>
<form name="myform">
<input type="button" name="mybutton" id="mybutton" >
</form>
</body>
</html>
<script>
document.getElementById("yonghu").onclick=dashu;
document.getElementById("bumen").onclick=dashu;
document.getElementById("xinxi").onclick=dashu;
document.getElementById("mybutton").onclick=cheshi;
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-03 · 知道合伙人互联网行家
关注
展开全部
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Simple Event Example</title>
<script type="text/javascript">
function addEventHandler(oNode, sEvt, fFunc, bCaptures) {
if (typeof (window.event) != "undefined") {
oNode.attachEvent("on" + sEvt, fFunc);
}
else {
oNode.addEventListener(sEvt, fFunc, bCaptures);
}
}
function onLinkClicked(e) {
alert('You clicked the link');
}
function setUpClickHandler() {
addEventHandler(document.getElementById('clickLink'), "click", onLinkClicked, false);
}
addEventHandler(window, "load", setUpClickHandler, false);
</script>
</head>
<body>
<a href="#" title="click me" id="clickLink">Click Me!</a>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Simple Event Example</title>
<script type="text/javascript">
function addEventHandler(oNode, sEvt, fFunc, bCaptures) {
if (typeof (window.event) != "undefined") {
oNode.attachEvent("on" + sEvt, fFunc);
}
else {
oNode.addEventListener(sEvt, fFunc, bCaptures);
}
}
function onLinkClicked(e) {
alert('You clicked the link');
}
function setUpClickHandler() {
addEventHandler(document.getElementById('clickLink'), "click", onLinkClicked, false);
}
addEventHandler(window, "load", setUpClickHandler, false);
</script>
</head>
<body>
<a href="#" title="click me" id="clickLink">Click Me!</a>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
典型的还没加载就去定位
下面这段要写在</body>之前</form>之后
<script language="javascript" type="text/javascript" >
document.getElementById("yonghu").onclick=dashu;
document.getElementById("bumen").onclick=dashu;
document.getElementById("xinxi").onclick=dashu;
document.getElementById("mybutton".onclick=cheshi;
</script>
你写在前面,都还没有加载到那些元素,你怎么可能定位得到
下面这段要写在</body>之前</form>之后
<script language="javascript" type="text/javascript" >
document.getElementById("yonghu").onclick=dashu;
document.getElementById("bumen").onclick=dashu;
document.getElementById("xinxi").onclick=dashu;
document.getElementById("mybutton".onclick=cheshi;
</script>
你写在前面,都还没有加载到那些元素,你怎么可能定位得到
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询