InvalidArgumentError:由于属性中的非法值导致失败:0

时间:2016-06-06 23:12:53

标签: javascript html google-apps-script

我正在尝试编写地理测验并且它似乎不起作用。每当我尝试点击“提交”按钮时,它都会打印出InvalidArgumentError: Failed due to illegal value in property: 0。你有什么想法可能会这样吗?提前谢谢。

HTML:

<!DOCTYPE html>
    <html>
        <head>
            <base target="_top">
            <script>
                function send() {
                    var q1 = document.getElementById("q1").value;
                    var q2 = document.getElementById("q2").value;
                    var q3 = document.getElementById("q3").value;
                    var q4 = document.getElementById("q4").value;
                    var q5 = document.getElementById("q5").value;
                    var q6 = document.getElementById("q6").value;
                    var q7 = document.getElementById("q7").value;
                    var q8 = document.getElementById("q8").value;
                    var Email = document.getElementById("EmailAddress");
                    var Result = ("Results: 1. " + q1 + " 2. " + q2 + " 3. " + q3 + " 4. " + q4 + " 5. " + q5 + " 6. " + q6 + " 7. " + q7 + " 8. " + q8);
                    google.script.run.send(Email, Result);
                }
            </script>
            <script src="https://ws.sharethis.com/button/buttons.js">
            </script>
            <script>
                stLight.options({
                	publisher: "a788dcd1-6dfb-49ee-ba6c-3b6822d69fd8",
                	doNotHash: false,
                	doNotCopy: false,
                	hashAddressBar: false
                });
            </script>
            <style>
                .myButton {
                    -moz-box-shadow: inset 0px 39px 0px -24px #e67a73;
                    -webkit-box-shadow: inset 0px 39px 0px -24px #e67a73;
                    box-shadow: inset 0px 39px 0px -24px #e67a73;
                    background-color: #e4685d;
                    -moz-border-radius: 4px;
                    -webkit-border-radius: 4px;
                    border-radius: 4px;
                    border: 1px solid #ffffff;
                    display: inline-block;
                    cursor: pointer;
                    color: #ffffff;
                    font-family: Arial;
                    font-size: 15px;
                    padding: 6px 15px;
                    text-decoration: none;
                    text-shadow: 0px 1px 0px #b23e35;
                }
                .myButton:hover {
                    background-color: #eb675e;
                }
                .myButton:active {
                    position: relative;
                    top: 1px;
                }
                .myButton2 {
                    -moz-box-shadow: inset 0px -3px 7px 0px #29bbff;
                    -webkit-box-shadow: inset 0px -3px 7px 0px #29bbff;
                    box-shadow: inset 0px -3px 7px 0px #29bbff;
                    background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #2dabf9), color-stop(1, #0688fa));
                    background: -moz-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
                    background: -webkit-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
                    background: -o-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
                    background: -ms-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
                    background: linear-gradient(to bottom, #2dabf9 5%, #0688fa 100%);
                    filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#2dabf9', endColorstr='#0688fa', GradientType=0);
                    background-color: #2dabf9;
                    -moz-border-radius: 3px;
                    -webkit-border-radius: 3px;
                    border-radius: 3px;
                    border: 1px solid #9591ff;
                    display: inline-block;
                    cursor: pointer;
                    color: #ffffff;
                    font-family: Arial;
                    font-size: 15px;
                    padding: 6px 23px;
                    text-decoration: none;
                    text-shadow: 0px 1px 0px #263666;
                }
                .myButton2:hover {
                    background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0688fa), color-stop(1, #2dabf9));
                    background: -moz-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
                    background: -webkit-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
                    background: -o-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
                    background: -ms-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
                    background: linear-gradient(to bottom, #0688fa 5%, #2dabf9 100%);
                    filter: progid: DXImageTransform.Microsoft.gradient(startColorstr='#0688fa', endColorstr='#2dabf9', GradientType=0);
                    background-color: #0688fa;
                }
                .myButton2:active {
                    position: relative;
                    top: 1px;
                }
            </style>
        </head>
        <body>
            <font face="Verdana">
                <h1>
                    Geography Quiz
                </h1>
                <br/>
                <br/>
                Your teacher's email address:
                <input type="text" id="EmailAddress"/>
                <br/>
                <br/>
                <b>
                    Questions
                </b>
                <br/>
                <br/>
                Q (1): Which state has a climate suitable for growing citrus fruits—California or Maine?
                <br/>
                A:
                <input type="text" id="q1"/>
                <br/>
                <br/>
                Q (2): The North Atlantic current brings warm waters from the tropics to the west coast of which continent?
                <br/>
                A:
                <input type="text" id="q2"/>
                <br/>
                <br/>
                Q (3): Which Canadian province produces more than half of the country's manufactured goods?
                <br/>
                A:
                <input type="text" id="q3"/>
                <br/>
                <br/>
                Q (4): To visit the ruins of Persepolis, an ancient ceremonial capital of Persia, you would have to travel to what present-day country?
                <br/>
                A:
                <input type="text" id="q4"/>
                <br/>
                <br/>
                Q (5): What is the term for a part of an ocean or sea that cuts far into the bordering landmass and may contain one or more bays?
                <br/>
                A:
                <input type="text" id="q5"/>
                <br/>
                <br/>
                Q (6): Which country has the world's largest Muslim population—Indonesia or Mexico?
                <br/>
                A:
                <input type="text" id="q6"/>
                <br/>
                <br/>
                Q (7): The Rio Hondo forms a boundary between Mexico and which other country?
                <br/>
                A:
                <input type="text" id="q7"/>
                <br/>
                <br/>
                Q (8): Which lake is on the border between Chad and Cameroon?
                <br/>
                A:
                <input type="text" id="q8"/>
                <br/>
                <br/>
                <button onclick="send(); document.write('Thanks! Your teacher will receive your results in an email.')" class="myButton">
                    Submit
                </button>
                <br/>
                <br/>
                <br/>
                <br/>
                <span class='st_facebook_hcount'>
                </span>
                <span class='st_twitter_hcount'>
                </span>
                <span class='st_googleplus_hcount'>
                </span>
                <br/>
                <br/>
                <footer>
                    <font size="1px">
                        Posted by: Yona Klatchko | Contact information:
                        <a href="mailto:yona.klatchko@gmail.com">
                            yona.klatchko@gmail.com
                        </a>
                    </font>
                </footer>
            </font>
        </body>
    </html>

Google-Apps-Script doGet()函数:

function doGet() {
    return(HtmlService.createTemplateFromFile('Index.html').evaluate().setTitle('Geography Quiz').setSandboxMode(HtmlService.SandboxMode.IFRAME)); 
}

Google-Apps-Script send()函数:

function send(Email, Result) {
    MailApp.sendEmail(Email, Result);
}

1 个答案:

答案 0 :(得分:3)

send()函数中,您正在提取并发送电子邮件dom元素而不是字符串值:

var Email = document.getElementById("EmailAddress");返回dom元素。

将其更改为:

var Email = document.getElementById("EmailAddress").value;

将解决invalidArgumentError

的问题

下一个问题是您将不会收到该电子邮件。 那是因为在你的代码中:

function send(Email, Result) {
    MailApp.sendEmail(Email, Result);
}

您正在传递两个参数,但正如您在documentation中看到的那样,第三个参数不是可选的,您需要将第三个参数作为正文传递。

MailApp.sendEmail(Email, Result, "");

将以空身发送电子邮件。