在 Asp.net 母版页中分配 javascript 事件
我的网页顶部有一个菜单栏,带有 4-5 个 asp.net 按钮,代码包含在母版页中。我希望所有按钮在鼠标悬停时执行某些操作,因此我在循环中分配事件,如下所示:
function pageLoad() {
var buttons = document.getElementsByClass("headerButton");
for (i = 0; i < buttons.length; i++) {
var b = buttons[i];
b.onmouseover = function (element) {
return function () {
element.style.fontWeight = "bold";
}
} (b);
b.onmouseout = function (element) {
return function () {
element.style.fontWeight = "normal";
}
} (b);
}
当然,这仅适用于内容页面。我相信 Page_Load 永远不会在母版页上触发,因此当我尝试将此代码放在母版页上时,什么也不会发生。有人知道这是如何做到的吗?
I have a menu bar across the top of my web page with 4-5 asp.net buttons, the code is contained in the master page. I want all the buttons to do something on mouse over, so I am assigning the events in a loop like so:
function pageLoad() {
var buttons = document.getElementsByClass("headerButton");
for (i = 0; i < buttons.length; i++) {
var b = buttons[i];
b.onmouseover = function (element) {
return function () {
element.style.fontWeight = "bold";
}
} (b);
b.onmouseout = function (element) {
return function () {
element.style.fontWeight = "normal";
}
} (b);
}
Of course this only works on content pages. Page_Load never fires on the master page, I believe, so when I try putting this code on the master nothing ever occurs. Anyone know how this is meant to be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一定错过了一些东西...为什么你不直接用 CSS 来处理这个问题呢?
I must be missing something... Why would you just not handle this with CSS?