调用函数时,下拉菜单选项消失

时间:2015-12-16 09:40:42

标签: javascript html5 drop-down-menu google-apps-script

我正在尝试将下拉菜单选项传递给我的Javascript文件中的函数。这有效,但是只要我点击提交按钮,下拉菜单选项就会被删除,而我会留下一个空的下拉菜单。 (这似乎只发生在Google脚本中的应用程序时。)

有没有想过为什么会这样?使用apps脚本有更好的方法吗?

非常感谢任何帮助。

function doSomething(){
var x = document.getElementById("API_key").value;
document.getElementById("API_key").innerHTML = x;

var subdomain =document.getElementById("subdomain").value;
document.getElementById("subdomain").innerHTML = subdomain;

var state = document.getElementById("stateSelect").value;
 document.getElementById("stateSelect").innerHTML = state;

google.script.run.getInfo(x,subdomain,state);

}
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
  <head>
    <base target="_top">
  </head>
  <body>
  
  <P ALIGN=Center>

 <BLOCKQUOTE>
 
 
 <P ALIGN=Left>
    <div class="inline form-group">
      <label for="API_key">API Key</label>
      <input type="text" id="API_key" style="width: 150px;" value="Enter API key here!">
    </div>
    
    
  <P ALIGN=Left> 
     <div class="inline form-group">
      <p>
      <label for="Subdomain">Subdomain</label>
      <input type="text" id="subdomain" style="width: 150px;">
      </p>
    </div>
    
<select id ="stateSelect">
  <option value="">All</option>
  <option value="&state=active">Active</option>
  <option value="&state=past_due">Past Due</option>
  <option value="&state=canceled">Canceled</option>
  <option value="&state=expired">Expired</option>
  <option value="&state=trialing">Trialing</option>
</select>
    
<div>
  <input type="checkbox" id="Product Info" checked>
  <label for="Product Info">Product Info</label>
</div>
  
<div>
  <input type="checkbox" id="Shipping Info">
  <label for="Shipping Info">Shipping Info</label>
</div>
    
    
     <div>
     <p>
    <input class="action" type="button" onclick="doSomething()" value="Get Info!" />
    </p>
    </div>
    </BLOCKQUOTE>
  </body>
</html>

2 个答案:

答案 0 :(得分:0)

function doSomething(){
var x = document.getElementById("API_key").value;


var subdomain =document.getElementById("subdomain").value;


var state = document.getElementById("stateSelect").value;
 
 

google.script.run.getInfo(x,subdomain,state);

}
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
  <head>
    <base target="_top">
  </head>
  <body>
  
  <P ALIGN=Center>

 <BLOCKQUOTE>
 
 
 <P ALIGN=Left>
    <div class="inline form-group">
      <label for="API_key">API Key</label>
      <input type="text" id="API_key" style="width: 150px;" value="Enter API key here!">

    </div>
    
    
  <P ALIGN=Left> 
     <div class="inline form-group">
      <p>
      <label for="Subdomain">Subdomain</label>
      <input type="text" id="subdomain" style="width: 150px;">

      </p>
    </div>
    
<select id ="stateSelect">
  <option value="">All</option>
  <option value="&state=active">Active</option>
  <option value="&state=past_due">Past Due</option>
  <option value="&state=canceled">Canceled</option>
  <option value="&state=expired">Expired</option>
  <option value="&state=trialing">Trialing</option>
</select>

    
<div>
  <input type="checkbox" id="Product Info" checked>
  <label for="Product Info">Product Info</label>
</div>
  
<div>
  <input type="checkbox" id="Shipping Info">
  <label for="Shipping Info">Shipping Info</label>
</div>
    
    
     <div>
     <p>
    <input class="action" type="button" onclick="doSomething()" value="Get Info!" />
    </p>
    </div>
    </BLOCKQUOTE>
  </body>
</html>

答案 1 :(得分:0)

这不是必需的。只需评论并检查

 function doSomething(){
  var x = document.getElementById("API_key").value;
  document.getElementById("API_key").innerHTML = x;

  var subdomain =document.getElementById("subdomain").value;
  document.getElementById("subdomain").innerHTML = subdomain;

   var state = document.getElementById("stateSelect").value;
 //document.getElementById("stateSelect").innerHTML = state;

   google.script.run.getInfo(x,subdomain,state);

}