English 中文(简体)
参考外部js文档中的d子
原标题:Referencing a td tag with an external js file

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
}

你们可以看到,总损失很少。

问题回答
document.getElementById( lifeCalculatorButton ).onmouseover = function() { ... };

......

或者,你可以走高路:

<td id="lifeCalculatorButton" onmouseover="MouseOver()">imagefoo</td>

使用 ElementById

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

EDIT:改为:P





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签