开发者

Javascript web browser script not working

开发者 https://www.devze.com 2023-03-15 14:29 出处:网络
Internet Explorer 7 does not handle buttons correctly since it sends the text between <button> and </button>rath开发者_Go百科er than the value. (Weird but true.) This Javascript is suppose

Internet Explorer 7 does not handle buttons correctly since it sends the text between <button> and </button>rath开发者_Go百科er than the value. (Weird but true.) This Javascript is supposed to correct this by sending the value of the button onClick. But it does not work. Can anybody see the error ?

I use this to attach the Javascript file in HTML5 :

<script src="buttonfix.js"></script>

Contents of buttonfix.js :

function runonclick()
{
    var count = 0;
    var formlength = this.form.elements.length;
    while(count < formlength)
    {
        if(this.form.elements[count].tagName === "button")
        {
            this.value = this.attributes.getNamedItem("value").nodeValue;
        }

        count++;
    }
}

function buttonfix()
{
    var buttonarray = document.getElementsByTagName("button");

    var count = 0;
    var buttonarraylength = buttonarray.length;
    while(count < buttonarraylength)
    {
        buttonarray[count].onClick = runonclick();

        count++;
    }
}

window.attachEvent("onload", buttonfix());


I suggest you to try:

if(this.form.elements[count].tagName.toLowerCase == "button");

instead of:

if(this.form.elements[count].tagName == "button")

because the tagName property generally returns an uppercased string.

Another line does not work:

buttonarray[count].onClick = runonclick();

As JavaScript it is a case-sensitive language, you have to use the standard name of the event (onclick).

buttonarray[count].onclick = runonclick();

However, you may still to use onClick in your HTML (but not XHTML).

0

精彩评论

暂无评论...
验证码 换一张
取 消