我已经构建了一个代码,它创建了一个弹出式窗口和一个下拉选择器。效果很好。问题来自试图将用户从html文件中选择的内容传递回一个不同的函数作为参数。
传回只会在记录器中返回"null“。
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<span>Select your most perferred remote control comms. protocol from the list below.</span>
<form>
<select name="Protocols" onchange="parseBackFunc()">
<option value=17>Modbus</option>
<option value=18>SCPI</option>
<option value=19>CAN open</option>
<option value=20>Profibus</option>
<option value=21>Profinet</option>
<option value=22>EtherCAT</option>
</select>
</form>
<br>
<input type="button" onClick="google.script.host.close();" value="Submit" />
</body>
</html>
<script type="text/javascript">
function parseBackFunc() {
google.script.run.htmlReturn(document.forms[0].value);
}
</script>
有一次,我在htmlReturn
函数的参数中手动输入了一些数字,实际上,这些数字出现在记录器中。有人能指出我如何正确地参考用户的选择吗?
发布于 2022-07-26 21:20:56
而不是
google.script.run.htmlReturn(document.forms[0].value);
使用
const select = document.querySelector('select[name="Protocols"]');
const value = select.options[select.selectedIndex].value;
const text = select.options[select.selectedIndex].text;
google.script.run.htmlReturn(value);
相关
https://stackoverflow.com/questions/73129606
复制相似问题