如何将运行时参数从html代码传递到javascript函数

如何将运行时参数从html代码传递到javascript函数,javascript,html,css,Javascript,Html,Css,重点是通过改变元素的背景色,在鼠标移动时将焦点放在网页的特定元素上 html格式如下: <html> <head> <base src="..... /> <script>....</script> <link..../> <title></title> </head> <body> <p style="font-size:20px;font-weight:bold"&g

重点是通过改变元素的背景色,在鼠标移动时将焦点放在网页的特定元素上

html格式如下:

<html>
<head>
<base src="..... />
<script>....</script>
<link..../>
<title></title>
</head>
<body>
<p style="font-size:20px;font-weight:bold"> Enter values or choose options 
in the form below .</p>
<div id="d1">

<form id="f1" action="" method="post">
<fieldset>
    <legend><a name="pdet"></a>Personal Details</legend>
    <table id="t1" width="400" height="auto" rows="4" cols="2">
        <tr id="tr1" onMouseMove ="focus(tr1)" onMouseOut ="original(tr1)">
            <td><label for="fname">First Name :<label></td>
            <td><input type="text" id="fname" col="30"></input></td>
        </tr>
        <tr id="tr2" onMouseMove ="focus(tr2)" onMouseOut ="original(tr2)">
            <td><label for="lname">Last Name : </label></td>
            <td><input type="text" id="lname" col="30"></input></td>                
        </tr>
    </table>
</fieldset>
</form>
</div>
<br/>
</body>
</html>
阅读之前关于同一主题的ans,建议使用“focus(this)”或“focus(this.id)”作为参数分别传递元素本身或元素的id。我试过了,但没用


有人能帮我解决这个问题吗?

我想你的主要问题可能是你使用的是
“e\u id”
(一个字符串)而不是
e\u id
(一个变量标识符)。

这只是引号使用不正确的问题

函数elfocus(e_id){
//不要在e_id周围使用引号来使用函数参数
var element=document.getElementById(e_id).style.backgroundColor=“蓝色”;
}
功能原件(e_id){
var element=document.getElementById(e_id).style.backgroundColor=“绿色”;
}
输入值或选择选项 在下面的表格中

个人资料 名字: 姓氏:
“e_id”是一个字符串,不是对变量的引用
function focus(e_id){
var element = document.getElementById("e_id").style.backgroundColor ="blue";
}

function original(e_id){
var element = document.getElementById("e_id").style.backgroundColor="green";
}