Javascript函数提交无法正常工作

时间:2016-06-26 17:33:05

标签: javascript html5 css3

function submit() {
    var text;
    do {
        text = "Não Completou o formelario";
    }
    while (x == "" && y == "");
    document.getElementById("Erros").innerHTML = text;

    var x = document.getElementById("PNome");
    var y = document.getElementById("UNome");
    var Person = function Person(first, last) {
        this.firstName = first;
        this.lastName = last;
    };
    Person.prototype.name = function() {
        return this.firstName + " " + this.lastName;
    };
    var Pessoa = new Person(x, y);
    document.getElementById("demo").innerHTML = Pessoa.name();
}

2 个答案:

答案 0 :(得分:1)

你返回x和y。

x=document.getElementById("a")

这意味着x是一个对象。如果您想要使用此对象的值

x=document.getElementById("a").value

答案 1 :(得分:0)

这有助于您:



<!DOCTYPE html>
<html>
    <head>
    </head>
    <body> 
        <form method="post" name="frm" onsubmit="return s()">
            first : <input type="text" id="PNome">
            <br><br>
            last  : <input type="text" id="UNome">
            <br><br>
            <button type="submit">Submit</button>
        </form>
        <p id="demo"></p>
        <p id="Erros"></p>
        <script>
            function s() {
                var x = document.getElementById("PNome");
                var y = document.getElementById("UNome");
                var text = "";
                if(x.value == "" && y.value == ""){
                     text = "Não Completou o formelario";
                     var Errors = document.getElementById("Erros").innerHTML = text;
                     return false;
                }
                  var Person=function Person(first,last)
                    {
                        this.firstName=first;
                        this.lastName=last;
                    };
                    Person.prototype.name=function(){
                        return this.firstName + " " + this.lastName;
                    };
                var Pessoa=new Person(x.value,y.value);
                document.getElementById("demo").innerHTML=Pessoa.name();
                return false;
            }
        </script>
    </body>
</html>
&#13;
&#13;
&#13;