-5
<!DOCTYPE html>
<html>
<head>
<script language="javascript" type="text/javascript"> 

function changeValue()
{
    var list, index, element;
    list = document.getElementsByClassName('box-title');
    for (index = 0; index < list.length; ++index){
        element = list[index].innerHTML;
        if(element == "Related Products"){
            list[index].innerHTML = "Choose Extra To make It More Special";
            alert("Page is loaded");
        }
    }
} 
</script>
</head>
<body onload =”changeValue()”&gt;
<div class="box-title">Related Products</div>

</body>
</html> 
4

3 回答 3

1

Mayby you have to remove the space between onload and = and change the weird double quote (also known as 'smart quotes')

So this:

<body onload =”changeValue()”&gt;

will be this:

<body onload="changeValue()">
于 2012-11-19T22:22:26.000 回答
0

Have you tried changing the ++ operator?

<!DOCTYPE html>
<html>
<head>
<script language="javascript" type="text/javascript"> 

function changeValue()
{
 var list, index, element;
 list = document.getElementsByClassName('box-title');
 for (index = 0; index < list.length; index++)
 {
  element = list[index].innerHTML;
    if(element == "Related Products")
{
  list[index].innerHTML = "Choose Extra To make It More Special";
  alert("Page is loaded");
}
}

} 
</script>
</head>
<body onload =”changeValue()”&gt;
<div class="box-title">Related Products</div>

</body>
</html> 
于 2012-11-19T22:22:04.893 回答
0

There's a number of reasons for which it may not be working.

For example, getElementsByClassName() might be unsupported by the browser.

于 2012-11-19T22:24:24.667 回答