您的位置:首页 > Web前端 > CSS

JS修改当前控件样式&为控件追加事件

2013-08-25 23:21 375 查看
先搁这吧,今天太晚了,以后再加注释和修整吧。不幸搜到的朋友就别看了

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function set() {
var obj = document.getElementById("fy");

//obj.attachEvent('onfocus', add); //在原先事件上添加
//obj.setAttribute('onfocus',add); //会替代原有事件方法
//obj.onfocus=add;                //等效obj.setAttribute('onfocus',add);

if (window.addEventListener) {
//其它浏览器的事件代码: Mozilla, Netscape, Firefox
//添加的事件的顺序即执行顺序 //注意用 addEventListener 添加带on的事件,不用加on
obj.addEventListener('focus', add, false);
}
else {
//IE 的事件代码 在原先事件上添加 add 方法
obj.attachEvent('onfocus', add);
}
}

function func(mess) {
alert(mess);
}

function changecss(e) {
if (e.className = "redcss") {
e.className = "likelink";
e.attachEvent('onclick', function () { func("2321"); }); //带参数
e.onmouseover = add

// e.addEventListener('mouseover', add, false);

}
}
function add() {

}
</script>
<style type="text/css">
.redcss {
color:red
}
.likelink {
width:20px;
color:blue;
text-decoration:;
cursor:pointer;        }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div style="width:30px">
<a id="link" class="redcss" runat="server" onclick="changecss(this)"><h1>good</h1> </a>
</div>
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐