HTML调用JS函数

<script type="text/javascript">
function mouse1()
{
document.getElementById("table1").bgColor = "#FFFF80";
}
function mouse2()
{
document.getElementById("table1").bgColor = "#999999";
}
</script>
<body>
<table id="table1" onmouseout="mouse2();" onmousemove="mouse1();" bgcolor="#999999">
</table>
<table id="table2" onmouseout="mouse2();" onmousemove="mouse1();" bgcolor="#999999">
</table>
</body>
======================
function mouse1(),
function mouse2()
如何实现写一次就可以多次调用呢? 求大神帮忙...感激不尽!

  操作步骤:

  1、打开Dreamweaver软件,然后在创建新项目下选择HTML;

  2、点击“文件”选项,然后点击“另存为”,将文件命名为test,并将其保存在电脑桌面上;

  3、编写一个基本的html文件,该html文件包含一个用户名及一个密码输入文本框和一个确定以及一个取消按钮;

  4、在title标签下插入<script language="JavaScript">js代码</script>,然后在html中调用js函数;

  5、完成js代码编写及html调用js代码后保存tset.html文件,然后在浏览器中打开test.html文件,检查js代码执行的效果;

  6、在Dreamweaver软件中新建一个check.js文件(方法同html文件新建),在check文件中输入校验函数;

  7、然后在test.html的title标签下引用check.js文件;

  8、在程序中引用check.js文件中的js函数,然后在浏览器中刷新test.hmtl文件,然后在username的输入框中输入非法字符来检验js代码。

       

       

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-11

zhou2003737  写的就挺好的。

我给你来个简单的,改动不大的。


<script type="text/javascript">
    function mouse(v , flag)
    {
    if(flag==1)
        v.bgColor = "#FFFF80";
    else
        v.bgColor = "#999999";
    }  
</script>
<body>
<table id="table1" onmouseout="mouse(this,1);" onmousemove="mouse(this,2);" bgcolor="#999999">
<tr><td>1</td></tr>
</table>
<table id="table2" onmouseout="mouse(this,1);" onmousemove="mouse(this,2);" bgcolor="#999999">
<tr><td>2</td></tr>
</table>
</body>

本回答被提问者和网友采纳
第2个回答  2014-10-15
<script type="text/javascript">
    function mouse1(var id)
    {
        document.getElementById(id).bgColor = "#FFFF80";
    }
   function mouse2(var id)
   {
        document.getElementById(id).bgColor = "#999999";
    }
</script>
<body>
<table id="table1" onmouseout="mouse2("table1");" onmousemove="mouse1("table1");" bgcolor="#999999">
</table>
<table id="table2" onmouseout="mouse2("table2");" onmousemove="mouse1("table2");" bgcolor="#999999">
</table>
</body>

我懂你,你传一个标签的id进来就可以实现多次调用了。我帮你优化了一下。

第3个回答  2014-10-15
怎么俩个都是给table1设背景颜色??不是应该各自对应的table颜色吗??

你只要在鼠标经过的时候吧对象传入函数就好了
js:
<script language="javascript">
function mouse1(obj)
{
//document.getElementById("table1").bgColor = "FFFF80"
document.getElementById(obj).style.fontSize = "22px";
}
function mouse2(obj)
{
document.getElementById(""+obj+"").style.backgroundColor = "#ffffff";
}

</script>

html:
<table id="table1" onmouseout="mouse2('table1');" width="500" height="50" onmousemove="mouse1('table1');" bgcolor="#999999">
<tr><td>2222</td></tr>
</table>
<br />
<table id="table2" onmouseout="mouse2('table2');" height="50" width="500" onmousemove="mouse1('table2');" bgcolor="#999999">
<tr><td>1111</td></tr>
</table>
注意引号。。。
第4个回答  2014-10-15
主要是id换成class 群主选择器 之后js 换成 document.getElementByClassName("").
如下:

<script type="text/javascript">
function mouse1()
{
document.getElementByClassName("table1").bgColor = "#FFFF80";
}
function mouse2()
{
document.getElementByClassName("table1").bgColor = "#999999";
}
</script>
<body>
<table class="table1" onmouseout="mouse2();" onmousemove="mouse1();" bgcolor="#999999">
</table>
<table class="table2" onmouseout="mouse2();" onmousemove="mouse1();" bgcolor="#999999">
</table>
</body>
======================
function mouse1(),
function mouse2()

代码没查看效果 你自己写的 自己试试吧

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网