动态更改图像的 JavaScript 代码适用于 IE 而不是 FF、Chrome 等:(

发布于 2024-12-05 00:54:53 字数 15367 浏览 1 评论 0原文

通常我听说代码在 IE 之外的环境下工作,但我遇到了相反的问题。

这是链接:

http://www.underagedriven.co.uk/ins/timeclick2.php

以及代码的快照,该代码在 IE 下不会出现任何错误,但不会与其他任何东西(Opera、iPhone Safari、Chrome、FF)一起使用,

我知道这会是一些愚蠢的事情,但我已经为此工作了一整天(我不是一个合适的编码员)当它不玩球时,我的眼睛有点呆滞。

任何帮助都可以为我指出正确的方向:)

谢谢,里克

<html>
<head>

<script type="text/javascript">

var arr = new Array();                                  // Create our array
var convexisting = " ";                                 // Create a blank variable we check later

if (!Array.prototype.indexOf)                               // IE8 and below
{ 
    Array.prototype.indexOf = function(elt /*, from*/) 
    { 
        var len = this.length >>> 0; 

        var from = Number(arguments[1]) || 0; 
        from = (from < 0) 
            ? Math.ceil(from) 
            : Math.floor(from); 
        if (from < 0) 
        from += len; 

        for (; from < len; from++) 
        { 
        if (from in this && 
            this[from] === elt) 
            return from; 
        } 
        return -1; 
    }; 
}   

function toggleimg(itemname)
{
    if (document.getElementById(itemname).src == 'http://www.underagedriving.co.uk/ins/yellow.gif')     // If its yellow that means its not set
    {
        document.getElementById(itemname).src = 'http://www.underagedriving.co.uk/ins/blue.gif';    // Change colour to blue
        arr.push(itemname);                                         // Add item to array
        }
    else
    {
        document.getElementById(itemname).src = 'http://www.underagedriving.co.uk/ins/yellow.gif';  // If its already blue, deselect it by turning yellow
        arr.splice(arr.indexOf(itemname), 1);                               // Remove it from array

    }   
}

function checkform(form)                                            // On submit fix the array to send to PHP
{
    form.availabilityarray.value = arr.join(",");                   // Concat our array data in a CSV string to submit via the form
        return true ;                                   // Allow submitting of the form data
}

function preprocess()                                   // Has to be a function after body load
{
        // If array ready to be processed

    if (convexisting != " ")                            // Check our test var is not blank
    {
        var arr = convexisting.split(",");                  // Split our CSV data for the grid back into an array
        for (var i = 0; i < arr.length; i++) toggleimg(arr[i]);         // For each entry in array run toggleimg
    }
}   

</script>

<body onload="javascript:preprocess();">

<form name="claimform" method="POST" action="http://www.underagedriving.co.uk/ins/timeclick2.php" enctype="multipart/form-data" onsubmit="return checkform(this);">

<table width="700" cellspacing=0 cellpadding=0 border=0>
<tr>
<td width="200">&nbsp;</td><td width="500"><img src='hours.gif' border=0></td>
</tr>    

<tr><td align='right'> Fri 07/10/2011 &nbsp; </td><td><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col00');"><img src='yellow.gif' name='20111007row05col00' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col01');"><img src='yellow.gif' name='20111007row05col01' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col02');"><img src='yellow.gif' name='20111007row05col02' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col03');"><img src='yellow.gif' name='20111007row05col03' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col04');"><img src='yellow.gif' name='20111007row05col04' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col05');"><img src='yellow.gif' name='20111007row05col05' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col06');"><img src='yellow.gif' name='20111007row05col06' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col07');"><img src='yellow.gif' name='20111007row05col07' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col08');"><img src='yellow.gif' name='20111007row05col08' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col09');"><img src='yellow.gif' name='20111007row05col09' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col10');"><img src='yellow.gif' name='20111007row05col10' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col11');"><img src='yellow.gif' name='20111007row05col11' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col12');"><img src='yellow.gif' name='20111007row05col12' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col13');"><img src='yellow.gif' name='20111007row05col13' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col14');"><img src='yellow.gif' name='20111007row05col14' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col15');"><img src='yellow.gif' name='20111007row05col15' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col16');"><img src='yellow.gif' name='20111007row05col16' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col17');"><img src='yellow.gif' name='20111007row05col17' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col18');"><img src='yellow.gif' name='20111007row05col18' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col19');"><img src='yellow.gif' name='20111007row05col19' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col20');"><img src='yellow.gif' name='20111007row05col20' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col21');"><img src='yellow.gif' name='20111007row05col21' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col22');"><img src='yellow.gif' name='20111007row05col22' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col23');"><img src='yellow.gif' name='20111007row05col23' border=0></a></td></tr>
<tr><td align='right'> Sat 08/10/2011 &nbsp; </td><td><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col00');"><img src='yellow.gif' name='20111008row06col00' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col01');"><img src='yellow.gif' name='20111008row06col01' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col02');"><img src='yellow.gif' name='20111008row06col02' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col03');"><img src='yellow.gif' name='20111008row06col03' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col04');"><img src='yellow.gif' name='20111008row06col04' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col05');"><img src='yellow.gif' name='20111008row06col05' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col06');"><img src='yellow.gif' name='20111008row06col06' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col07');"><img src='yellow.gif' name='20111008row06col07' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col08');"><img src='yellow.gif' name='20111008row06col08' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col09');"><img src='yellow.gif' name='20111008row06col09' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col10');"><img src='yellow.gif' name='20111008row06col10' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col11');"><img src='yellow.gif' name='20111008row06col11' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col12');"><img src='yellow.gif' name='20111008row06col12' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col13');"><img src='yellow.gif' name='20111008row06col13' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col14');"><img src='yellow.gif' name='20111008row06col14' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col15');"><img src='yellow.gif' name='20111008row06col15' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col16');"><img src='yellow.gif' name='20111008row06col16' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col17');"><img src='yellow.gif' name='20111008row06col17' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col18');"><img src='yellow.gif' name='20111008row06col18' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col19');"><img src='yellow.gif' name='20111008row06col19' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col20');"><img src='yellow.gif' name='20111008row06col20' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col21');"><img src='yellow.gif' name='20111008row06col21' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col22');"><img src='yellow.gif' name='20111008row06col22' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col23');"><img src='yellow.gif' name='20111008row06col23' border=0></a></td></tr>
<tr><td align='right'> Sun 09/10/2011 &nbsp; </td><td><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col00');"><img src='yellow.gif' name='20111009row07col00' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col01');"><img src='yellow.gif' name='20111009row07col01' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col02');"><img src='yellow.gif' name='20111009row07col02' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col03');"><img src='yellow.gif' name='20111009row07col03' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col04');"><img src='yellow.gif' name='20111009row07col04' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col05');"><img src='yellow.gif' name='20111009row07col05' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col06');"><img src='yellow.gif' name='20111009row07col06' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col07');"><img src='yellow.gif' name='20111009row07col07' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col08');"><img src='yellow.gif' name='20111009row07col08' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col09');"><img src='yellow.gif' name='20111009row07col09' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col10');"><img src='yellow.gif' name='20111009row07col10' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col11');"><img src='yellow.gif' name='20111009row07col11' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col12');"><img src='yellow.gif' name='20111009row07col12' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col13');"><img src='yellow.gif' name='20111009row07col13' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col14');"><img src='yellow.gif' name='20111009row07col14' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col15');"><img src='yellow.gif' name='20111009row07col15' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col16');"><img src='yellow.gif' name='20111009row07col16' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col17');"><img src='yellow.gif' name='20111009row07col17' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col18');"><img src='yellow.gif' name='20111009row07col18' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col19');"><img src='yellow.gif' name='20111009row07col19' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col20');"><img src='yellow.gif' name='20111009row07col20' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col21');"><img src='yellow.gif' name='20111009row07col21' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col22');"><img src='yellow.gif' name='20111009row07col22' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col23');"><img src='yellow.gif' name='20111009row07col23' border=0></a></td></tr>
<tr><td> <hr </td></tr>
</table>

<input type="hidden" name="availabilityarray" value="">
<input type="submit" value="Submit Hours">

</form>

</body>
</html>

Usually I hear about code working under things apart from IE but Ive got the opposite problem.

Here's the link :

http://www.underagedriving.co.uk/ins/timeclick2.php

And a snapshot of the code that doesnt kick any errors under IE but wont play ball with anything else (Opera, iPhone Safari, Chrome, FF)

I know its going to be something daft but having worked on this all day (Im not a proper coder) when it wasnt playing ball my eyes kinda glazed over .

Any help appreciated pointing me in the right direction :)

Thanks, Rik

<html>
<head>

<script type="text/javascript">

var arr = new Array();                                  // Create our array
var convexisting = " ";                                 // Create a blank variable we check later

if (!Array.prototype.indexOf)                               // IE8 and below
{ 
    Array.prototype.indexOf = function(elt /*, from*/) 
    { 
        var len = this.length >>> 0; 

        var from = Number(arguments[1]) || 0; 
        from = (from < 0) 
            ? Math.ceil(from) 
            : Math.floor(from); 
        if (from < 0) 
        from += len; 

        for (; from < len; from++) 
        { 
        if (from in this && 
            this[from] === elt) 
            return from; 
        } 
        return -1; 
    }; 
}   

function toggleimg(itemname)
{
    if (document.getElementById(itemname).src == 'http://www.underagedriving.co.uk/ins/yellow.gif')     // If its yellow that means its not set
    {
        document.getElementById(itemname).src = 'http://www.underagedriving.co.uk/ins/blue.gif';    // Change colour to blue
        arr.push(itemname);                                         // Add item to array
        }
    else
    {
        document.getElementById(itemname).src = 'http://www.underagedriving.co.uk/ins/yellow.gif';  // If its already blue, deselect it by turning yellow
        arr.splice(arr.indexOf(itemname), 1);                               // Remove it from array

    }   
}

function checkform(form)                                            // On submit fix the array to send to PHP
{
    form.availabilityarray.value = arr.join(",");                   // Concat our array data in a CSV string to submit via the form
        return true ;                                   // Allow submitting of the form data
}

function preprocess()                                   // Has to be a function after body load
{
        // If array ready to be processed

    if (convexisting != " ")                            // Check our test var is not blank
    {
        var arr = convexisting.split(",");                  // Split our CSV data for the grid back into an array
        for (var i = 0; i < arr.length; i++) toggleimg(arr[i]);         // For each entry in array run toggleimg
    }
}   

</script>

<body onload="javascript:preprocess();">

<form name="claimform" method="POST" action="http://www.underagedriving.co.uk/ins/timeclick2.php" enctype="multipart/form-data" onsubmit="return checkform(this);">

<table width="700" cellspacing=0 cellpadding=0 border=0>
<tr>
<td width="200"> </td><td width="500"><img src='hours.gif' border=0></td>
</tr>    

<tr><td align='right'> Fri 07/10/2011   </td><td><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col00');"><img src='yellow.gif' name='20111007row05col00' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col01');"><img src='yellow.gif' name='20111007row05col01' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col02');"><img src='yellow.gif' name='20111007row05col02' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col03');"><img src='yellow.gif' name='20111007row05col03' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col04');"><img src='yellow.gif' name='20111007row05col04' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col05');"><img src='yellow.gif' name='20111007row05col05' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col06');"><img src='yellow.gif' name='20111007row05col06' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col07');"><img src='yellow.gif' name='20111007row05col07' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col08');"><img src='yellow.gif' name='20111007row05col08' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col09');"><img src='yellow.gif' name='20111007row05col09' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col10');"><img src='yellow.gif' name='20111007row05col10' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col11');"><img src='yellow.gif' name='20111007row05col11' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col12');"><img src='yellow.gif' name='20111007row05col12' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col13');"><img src='yellow.gif' name='20111007row05col13' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col14');"><img src='yellow.gif' name='20111007row05col14' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col15');"><img src='yellow.gif' name='20111007row05col15' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col16');"><img src='yellow.gif' name='20111007row05col16' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col17');"><img src='yellow.gif' name='20111007row05col17' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col18');"><img src='yellow.gif' name='20111007row05col18' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col19');"><img src='yellow.gif' name='20111007row05col19' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col20');"><img src='yellow.gif' name='20111007row05col20' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col21');"><img src='yellow.gif' name='20111007row05col21' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col22');"><img src='yellow.gif' name='20111007row05col22' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111007row05col23');"><img src='yellow.gif' name='20111007row05col23' border=0></a></td></tr>
<tr><td align='right'> Sat 08/10/2011   </td><td><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col00');"><img src='yellow.gif' name='20111008row06col00' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col01');"><img src='yellow.gif' name='20111008row06col01' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col02');"><img src='yellow.gif' name='20111008row06col02' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col03');"><img src='yellow.gif' name='20111008row06col03' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col04');"><img src='yellow.gif' name='20111008row06col04' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col05');"><img src='yellow.gif' name='20111008row06col05' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col06');"><img src='yellow.gif' name='20111008row06col06' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col07');"><img src='yellow.gif' name='20111008row06col07' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col08');"><img src='yellow.gif' name='20111008row06col08' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col09');"><img src='yellow.gif' name='20111008row06col09' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col10');"><img src='yellow.gif' name='20111008row06col10' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col11');"><img src='yellow.gif' name='20111008row06col11' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col12');"><img src='yellow.gif' name='20111008row06col12' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col13');"><img src='yellow.gif' name='20111008row06col13' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col14');"><img src='yellow.gif' name='20111008row06col14' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col15');"><img src='yellow.gif' name='20111008row06col15' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col16');"><img src='yellow.gif' name='20111008row06col16' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col17');"><img src='yellow.gif' name='20111008row06col17' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col18');"><img src='yellow.gif' name='20111008row06col18' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col19');"><img src='yellow.gif' name='20111008row06col19' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col20');"><img src='yellow.gif' name='20111008row06col20' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col21');"><img src='yellow.gif' name='20111008row06col21' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col22');"><img src='yellow.gif' name='20111008row06col22' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111008row06col23');"><img src='yellow.gif' name='20111008row06col23' border=0></a></td></tr>
<tr><td align='right'> Sun 09/10/2011   </td><td><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col00');"><img src='yellow.gif' name='20111009row07col00' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col01');"><img src='yellow.gif' name='20111009row07col01' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col02');"><img src='yellow.gif' name='20111009row07col02' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col03');"><img src='yellow.gif' name='20111009row07col03' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col04');"><img src='yellow.gif' name='20111009row07col04' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col05');"><img src='yellow.gif' name='20111009row07col05' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col06');"><img src='yellow.gif' name='20111009row07col06' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col07');"><img src='yellow.gif' name='20111009row07col07' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col08');"><img src='yellow.gif' name='20111009row07col08' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col09');"><img src='yellow.gif' name='20111009row07col09' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col10');"><img src='yellow.gif' name='20111009row07col10' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col11');"><img src='yellow.gif' name='20111009row07col11' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col12');"><img src='yellow.gif' name='20111009row07col12' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col13');"><img src='yellow.gif' name='20111009row07col13' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col14');"><img src='yellow.gif' name='20111009row07col14' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col15');"><img src='yellow.gif' name='20111009row07col15' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col16');"><img src='yellow.gif' name='20111009row07col16' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col17');"><img src='yellow.gif' name='20111009row07col17' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col18');"><img src='yellow.gif' name='20111009row07col18' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col19');"><img src='yellow.gif' name='20111009row07col19' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col20');"><img src='yellow.gif' name='20111009row07col20' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col21');"><img src='yellow.gif' name='20111009row07col21' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col22');"><img src='yellow.gif' name='20111009row07col22' border=0></a><a href="javascript:void(0)" onclick="javascript:toggleimg('20111009row07col23');"><img src='yellow.gif' name='20111009row07col23' border=0></a></td></tr>
<tr><td> <hr </td></tr>
</table>

<input type="hidden" name="availabilityarray" value="">
<input type="submit" value="Submit Hours">

</form>

</body>
</html>

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

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

发布评论

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

评论(2

絕版丫頭 2024-12-12 00:54:53

name= 属性在 标记上没有意义。如果您真正想要的是 id,请显式设置 id=。

您可能想熟悉 jQuery JS 库。它使很多类似的任务变得更加容易。

The name= attribute is meaningless on the <img> tags. If what you actually want is an id, then set the id= explicitly.

You may want to familiarize yourself with the jQuery JS library. It makes a lot of tasks like this much easier.

德意的啸 2024-12-12 00:54:53

您的问题是您正在使用 name 属性的值,但将其与 getElementById 一起使用,后者适用于 id 属性。由于每个 name 属性值都是唯一的,因此您只需将它们更改为 id 属性,代码就应该可以工作。或者您可以将调用更改为 getElementByIdgetElementsByName

由于 getElementsByName 返回一个集合,如果您采用该方法,您将需要选择返回集合的第一个成员,如下所示:

if (document.getElementsByName(itemname)[0].src ...)

但为了稳健,您需要:

var el = document.getElementsByName(itemname)[0];
if (el && el.src == ...) {
    ...
}

应采用类似的方法调用getElementById

使用 getElementById 的代码可以在 IE(以及一些模仿其行为的浏览器)中运行,因为它总是混淆 name 和 id 属性,将它们本质上视为同一事物。它不适用于符合标准的浏览器,并且可能不适用于标准模式下的 IE 9。

Your problem is that you are using the value of the name attribute but using it with getElementById, which works on the id attribute. Since each name attribute value is unique, you can just change them to id attributes and the code should work. Or you can change the call to getElementById to getElementsByName.

Since getElementsByName returns a collection, if you adopt that approach you'll need to select the first member of the returned collection, something like:

if (document.getElementsByName(itemname)[0].src ...)

But to be robust, you would need:

var el = document.getElementsByName(itemname)[0];
if (el && el.src == ...) {
    ...
}

A similar approach should be adopted with the call to getElementById.

The code using getElementById works in IE (and some browsers that mimic its behaviour) because it has always confused name and id attributes, treating them essentially as the same thing. It doesn't work in standards compliant browsers, and probably won't work in IE 9 in standards mode.

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