Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改后台javascript函数不工作_Javascript - Fatal编程技术网

更改后台javascript函数不工作

更改后台javascript函数不工作,javascript,Javascript,下面的代码似乎编译时没有任何错误,但changebackground函数不起作用。当你点击它时,它什么也不做。 我不认为语法有问题,但不能肯定。没有错误,只是单击单元格时没有响应。 MyClick起作用,而tChangeBackground不起作用 有什么想法吗 <html><body> <head> <style> table,th { border:1px solid black font-size: 15px; font-family:

下面的代码似乎编译时没有任何错误,但changebackground函数不起作用。当你点击它时,它什么也不做。 我不认为语法有问题,但不能肯定。没有错误,只是单击单元格时没有响应。 MyClick起作用,而tChangeBackground不起作用

有什么想法吗

<html><body>
<head>
<style>
table,th
{ 
border:1px solid black
font-size:  15px;
font-family: Arial;
font-weight: bold;
empty-cells: show;
}
</style>
<style>
td
{ 
font-size: 10px;
font-weight: normal;
font-family: Arial;
border:1px solid black;
empty-cells: show;
align = "middle;"
}
</style>
<style>
p
{ 
font-size: 18px;
font-weight: bold;
font-family: Arial;
}
</style>
<style>
a.1{ text-decoration:none;color:WindowText}
</style>
<style>
#header{ display:block;top:0px;left:0px;width:100%;height: 112px;position:fixed;background-color: #ffffff;border:1px solid #888;}
</style>
<style>
#content{ margin:113px 0px 0px 0px;display:block;border:1px solid #888;}
</style>


<script type="text/javascript"> function myClick(args) {    window.clipboardData.setData('text',args.toString());   }</script>

<script type="text/javascript"> function changeBackground() {document.getElementById(cellID).style.borderColor = "2px solid red";   }</script>


</head>
 <p>  Scanned Samples </p> <table></table></div>  <p> Rack: 202771 - _SMEYER_IND_AC_2D-02 </p>

<table> 

<thead> 

<tr> 
 <font size = "10"> </font> 

<th> </th>

<th>1</th>

<th>2</th>

<th>3</th>

<th>4</th>

<th>5</th>

<th>6</th>

<th>7</th>


</tr> 

</thead> 

<td> <font size = "2"><b>A</b></td>

<td><a class = "1" href = "#abcd"onclick="javascript:myClick('202772')"><center>A1<br>0<br>(202772)</center></td>
 <td id = "Cell9"><a class = "1" href = "#abcd"onclick=" javascript:myClick('202780') "; javascript:changeBackground('Cell9')"> <center> A2<br>0<br>(202780)</center> </td>

<td id = "Cell17"><a class = "1" href = "#abcd"onclick=" javascript:myClick('202788') "; javascript:changeBackground('Cell17')"> <center> A3<br>0<br>(202788)</center> </td>


<td id = "Cell25"><a class = "1" href = "#abcd"onclick=" javascript:myClick('202796') "; javascript:changeBackground('Cell25')"> <center> A4<br>0<br>(202796)</center> </td>


<td id = "Cell33"><a class = "1" href = "#abcd"onclick=" javascript:myClick('202804') "; javascript:changeBackground('Cell33')"> <center> A5<br>0<br>(202804)</center> </td>


<td id = "Cell41"><a class = "1" href = "#abcd"onclick=" javascript:myClick('202812') "; javascript:changeBackground('Cell41')"> <center> A6<br>0<br>(202812)</center> </td>


<td id = "Cell49"><a class = "1" href = "#abcd"onclick=" javascript:myClick('202820') "; javascript:changeBackground('Cell49')"> <center> A7<br>0<br>(202820)</center> </td>


</tr>
 </table> 
 </body></html>
您正在使用参数调用changeBackground,而函数定义中没有它。这里有一个例子

javascript:changeBackground('Cell9')"
这是您的函数定义

function changeBackground() {
    document.getElementById(cellID).style.borderColor = "2px solid red";   
}
试着把它改成

function changeBackground(cellID) {
    document.getElementById(cellID).style.borderColor = "2px solid red";   
}
而且,这种形式也很糟糕。您应该更喜欢样式表而不是样式标记,而且您有很多样式表。脚本标记也是如此。请将它们放在外部JavaScript文件中

另外,像这个例子一样,您经常使用内联javascript

onclick=" javascript:myClick('202812') "; javascript:changeBackground('Cell41')"
这使得HTML很难阅读。您应该改为使用事件侦听器,并将它们放在JavaScript文件中


此外,HTML5不支持中心和字体标记。

函数changeBackground不接受任何参数。尝试函数changeBackgroundcellID?内联JavaScript?这是什么1995年?说实话,这是糟糕的设计。多个样式和脚本标记,不推荐的HTML标记,太多的内联JavaScript。这个问题真的很难理解。