Javascript 无法更改image.src属性+;函数执行,但不返回值
请查看IndexQ3文件中的SPOT 1注释。这就是我的问题所在。当用户单击下一个问题按钮时Javascript 无法更改image.src属性+;函数执行,但不返回值,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,请查看IndexQ3文件中的SPOT 1注释。这就是我的问题所在。当用户单击下一个问题按钮时xxx() 执行并运行myFunc_3。后者有一些问题,我无法检测到,即使它是一个5行函数。我知道它是通过在电子表格中输入一个新值来执行的。我知道它有问题,因为它返回“undefined” 问题:我做错了什么 IndexQ3文件: <!DOCTYPE html> <html> <head> <base target="_top"> <
xxx()
执行并运行myFunc_3
。后者有一些问题,我无法检测到,即使它是一个5行函数。我知道它是通过在电子表格中输入一个新值来执行的。我知道它有问题,因为它返回“undefined”
问题:我做错了什么
IndexQ3文件:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<script>
function saveResponse() {return document.getElementById('text').value;}
function returnText () {return "New Text!"} //function that changes the xx element
//function returnSrc () {var aaaa = '"' + returnCellValue(6) + '"'} //this approach is not working
function xxx() //function that is run when user clics button Next Question
{
document.getElementById("xx").innerHTML = returnText(); //Works
//SPOT 1
//the next line of code works partly - the myFunc_3() does get and write the value correctly
//but the variable uu is undefined despite "return b"
var uu = google.script.run.myFunc_3(); //
if(typeof uu == typeof "asdf") {uu = "1"} else {uu = "2"} //src value will be changed to 2 because of undefined
//document.getElementById("img").src = "https://www.google.com/images/srpr/logo3w.png"
document.getElementById("img").src = uu; //the scr value comes out as undefined
}
</script>
<div style="width: 100%; display: table;">
<div style="display: table-row">
<div style="display: table-cell;"> <!-- width: 400px -->
<p id="xx"> Question:</p>
<br>
<p style="font-size: 14pt"><?!= returnCellValue(2) ?></p>
<br>
<textarea id="text" rows="10" cols="30" style="font-size: 14pt">Enter the response here..</textarea>
<br>
<input type="button" value="Save Response" onclick='google.script.run.myFunc_3(saveResponse())' />
<input type="button" value="Next Question" onclick='google.script.run.nextQuestion(); xxx()' />
</div>
<div style="display: table-cell;">
<br>
<img id="img" src="<?!= returnCellValue(6) ?>" alt="No Image" width="650">
</div>
</div>
</div>
</body>
</html>
大牛,谢谢你
如果还有其他人在为此挣扎,以下是我所做的。在函数xxx()中,我添加了google.script.run.withSuccessHandler(onSuccess.myFunc_3()
。然后在正文中添加脚本标记
function onSuccess(sss) {
var uu = sss;
document.getElementById("img").src = sss;
}
“[该函数]是异步的,不直接返回;但是,[它]可以将值作为传递给成功处理程序的参数返回给客户机”请看,Daniel,我不知道如何将您的注释标记为最佳答案,因此我们开始:这是最佳答案!
function onSuccess(sss) {
var uu = sss;
document.getElementById("img").src = sss;
}