链接替换按钮

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title>submitToLinks</title>
        <style type="text/css"></style>
        <script type="text/javascript" language="javascript" charset="utf-8" src="submitToLink.js"></script>
    </head>
    <body>
        <form action="nogo.php" method="POST">
            <label for="Mame">Name:</label>
            <input type="text" id="name" name="Name"/>
            <input type="submit" value="check"/>
            <input type="submit" value="send"/>
        </form>
        
    </body>
</html>

function submitToLinks(){
    
    if(!document.getElementById || !document.createTextNode){
        return false;
    }
    var inputs,i,newLink,newText;
    inputs = document.getElementsByTagName('input');
    alert(inputs.length);
    for(i=0;i<inputs.length;i++){
        if(inputs[i].getAttribute('type').toLowerCase() != 'submit'){
            continue;
            i++;
        }
        newLink = document.createElement('a');
        newText = document.createTextNode(inputs[i].getAttribute('value'));
        newLink.appendChild(newText);
        newLink.setAttribute('href','javascript:document.forms[0].submit()');
        inputs[i].parentNode.replaceChild(newLink,inputs[i]);
        if(i<inputs.length){
            i--;
        }
    }
}
window.onload = submitToLinks;


你可能感兴趣的:(链接替换按钮)