我呼叫了一個函式(這里命名為 xx1)并且我想回傳一個區域變數。但它回傳未定義。這是我的代碼
//in html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form>
<input id="e1" name="e1" value="aaa">
<input id="e2" name="e2" value="aaa">
<input id="e3" name="e3" value="aaa">
</form>
<script>
function bb(ff){
document.getElementById("e1").value=ff["e1"];
document.getElementById("e2").value=ff["e2"];
document.getElementById("e3").value=ff["e3"];
M.updateTextFields();
}
google.script.run.withSuccessHandler(bb)
.xx1();
</script>
</body>
</html>
//in code.gs
function xx1(){
var pp=[];
var obj={};
obj.e1="e1 hh";
obj.e2="e2 hh";
obj.e3="e2 hh";
pp.push[obj];
return pp;
}
為什么我無法恢復函式 xx1() 回傳的區域?
uj5u.com熱心網友回復:
.push是一個函式,但您正在使用索引訪問。pp.push[obj];應該pp.push(obj)
const x1 = () => {
var pp=[];
var obj={};
obj.e1="e1 hh";
obj.e2="e2 hh";
obj.e3="e2 hh";
pp.push[obj];
return pp;
}
const x2 = () => {
var pp=[];
var obj={};
obj.e1="e1 hh";
obj.e2="e2 hh";
obj.e3="e2 hh";
pp.push(obj);
return pp;
}
console.log ({x1: x1(), x2: x2()})
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/395753.html
標籤:javascript html
上一篇:洗掉后如何添加回元素?在Jquery中使用.removeAttr
下一篇:在HTML5進度元素中獲取間隙
