使用外部js文件引用td标签

发布于 2024-12-27 06:38:56 字数 356 浏览 2 评论 0原文

我正在尝试使用外部 Javascript 文件引用特定的 td id,但遇到了问题。我只是想创建一个简单的 mouseOver 事件,当用户将鼠标悬停在标记如下的表格中的图像上时,该事件将显示一些不同的内容:

<td id="lifeCalculatorButton">imagefoo</td>

在外部 Javascript 中,我会编写如下函数吗这个?:

function mouseOver(lifeCalculatorButton){
  //some code
}

正如你所看到的,我总体上有点迷失......

I'm trying to reference a specific td id with an external Javascript file and am having trouble. I'm just trying to create a simple mouseOver event that will display some different content when the user rolls over an image in a table that is labelled like this:

<td id="lifeCalculatorButton">imagefoo</td>

in the external Javascript would I write the function like this?:

function mouseOver(lifeCalculatorButton){
  //some code
}

I'm a little lost overall as you can see...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪眸﹌ 2025-01-03 06:38:56
document.getElementById('lifeCalculatorButton').onmouseover = function() { ... };

...应该有帮助;)

或者,你可以走奇怪的路线:

<td id="lifeCalculatorButton" onmouseover="MouseOver()">imagefoo</td>
document.getElementById('lifeCalculatorButton').onmouseover = function() { ... };

... should help ;)

Alternatively, you could go the quirky route:

<td id="lifeCalculatorButton" onmouseover="MouseOver()">imagefoo</td>
情深已缘浅 2025-01-03 06:38:56

使用 getElementById

var el = document.getElementById("lifeCalculatorButton");
el.onmouseover = function(){
  //somecode
}

编辑:稍微改变一下:P

use getElementById

var el = document.getElementById("lifeCalculatorButton");
el.onmouseover = function(){
  //somecode
}

EDIT: changed it a bit :P

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文