应用脚本按ID获取元素

时间:2017-09-12 18:33:55

标签: google-apps-script

enter image description here

我在应用脚本客户端html模板中有以下内容:

<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<div>
    <label for="optionList">Click me</label>
    <select id="optionList" name="email" onchange="optionChange()">
        <option>Loading...</option>
    </select>
</div>

我想使用以下方式捕获更改:

function optionChange() {
 mySelect = document.getElementById("optionList");
 console.log(mySelect)
 };

但我在控制台中看不到任何元素。

根据我尝试的一些例子中的其他一些样板代码:

mySelect = $(document).getElementById("optionList").value;

现在在控制台中我得到了:

TypeError: $(...).getElementById is not a function

至少我在控制台中看到了什么。什么是'$',我怎样才能使这个工作?

编辑:

谢谢,我已经做了您建议的更改,但仍然只是在控制台中看到与电子表格相关的帖子和​​获取语句。

1 个答案:

答案 0 :(得分:1)

您应该指定元素的value属性,所以

//based on your coding style
function optionChange() {
mySelect = document.getElementById("optionList");
mySelectValue = mySelect.value;
console.log(mySelectValue)
 };

//based on your coding style
function optionChange() {
mySelect = document.getElementById("optionList").value;
console.log(mySelect)
 };
相关问题