gpt4 book ai didi

javascript - 当包含参数时,函数调用不起作用

转载 作者:行者123 更新时间:2023-12-01 01:51:42 25 4
gpt4 key购买 nike

几周来我一直断断续续地试图解决这个问题。也许其他人会看到我错过的明显的东西。

此时我只是想验证该功能是否正常工作;除了检查从 HTML 按钮到函数的参数传递之外,我没有做任何其他事情。

这里有两个按钮在起作用。第一个发送参数,但不起作用——未调用 Logger.log("yeeHa") 语句。秒按钮不发送参数,但允许调用 Logger 语句。

function runSetup(projectTitle,projectMgr,projectSponsor,datepicker,weeks) {
//function runSetup() {
Logger.log("before the vars");
var ptitle = projectTitle;
var pMan = projectMgr;
var pSpon = projectSponsor;
var date = datepicker;
var wks = weeks;
var tHeader = "Project";
var mHeader = "Project Manager";
var sHeader = "Project Sponsor";
Logger.log("yeeHa");
}
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<head>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
<base target="_top">
</head>
<body>
<div id="container" style="padding: 10px; text-align:center;">

<strong>Project Information</strong>
<p></p>

<div class="inline form-group">
<label for="projectTitle">Project Title</label>
<input type="text" id="projectTitle" style="width: 150px;">
</div>
<p></p>
<div class="inline form-group">
<label for="projectMgr">Project Manager</label>
<input type="text" id="projectMgr" style="width: 150px;">
<br>
</div>

<div class="inline form-group">
<label for="projectSponsor">Project Sponsor</label><br>
<input type="text" id="projectSponsor" style="width: 150px;">
<p></p>

</div>

<input type="text" id="datepicker" value="start date">

<div class="inline form-group">
<label for="state">Weeks</label>
<input type="text" id="state" style="width: 40px;">
</div>

<p></p>
<!-- THIS BUTTON DOES NOT WORK -->
<input type="button" class="create" name="ganntSetup" value="Setup Gannt" onClick="google.script.run.runSetup
(document.getElementById('projectTitle').value;
document.getElementById('projectMgr').value;
document.getElementById('projectSponsor').value;
document.getElementById('datepicker').value;
document.getElementById('weeks').value;
)" />
<!-- THIS BUTTON WORKS BUT DOES NOT SEND NEEDED INFORMATION -->
<input type="button" class="create" name="ganntSetup2" value="Setup Gannt2" onClick="google.script.run.runSetup()"/>

<div>
<p></p>
<p></p>
<input type="button" name="Main Menu" value="Main Menu" onClick="google.script.run.mainSidebar()" />
</div>

</div>

<div style=
"width: 100%;
position: fixed;
bottom: 0;
width: 100%;
text-align:center;
background-color:black;
text-color:white;">
<p><a href="http://www.fastadmin.solutions" target="blank"><b>©FastAdmin Solutions</b></a></p>
</div>
</div>
</body>
</html>

不确定我错过了什么,不允许此处理。

最佳答案

您应该使用逗号 (,) 而不是分号 (;) 分隔要设置为函数参数的变量值。此外,具有周值的输入具有状态 ID,但您尝试使用 document.getElementById("weeks") 获取其值。

<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<head>

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
<base target="_top">
</head>
<body>
<div id="container" style="padding: 10px; text-align:center;">

<strong>Project Information</strong>
<p></p>

<div class="inline form-group">
<label for="projectTitle">Project Title</label>
<input type="text" id="projectTitle" style="width: 150px;">
</div>
<p></p>
<div class="inline form-group">
<label for="projectMgr">Project Manager</label>
<input type="text" id="projectMgr" style="width: 150px;">
<br>
</div>

<div class="inline form-group">
<label for="projectSponsor">Project Sponsor</label><br>
<input type="text" id="projectSponsor" style="width: 150px;">
<p></p>

</div>

<input type="text" id="datepicker" value="start date">

<div class="inline form-group">
<label for="weeks">Weeks</label>
<input type="text" id="weeks" style="width: 40px;">
<!--Changed id to weeks instead of state.-->
</div>

<p></p>
<!–– THIS BUTTON DOES NOT WORK ––>
<input type="button" class="create" name="ganntSetup" value="Setup Gannt" onClick="runSetup
(document.getElementById('projectTitle').value, document.getElementById('projectMgr').value, document.getElementById('projectSponsor').value,
document.getElementById('datepicker').value,
document.getElementById('weeks').value
)" />
<!–– THIS BUTTON WORKS BUT DOES NOT SEND NEEDED INFORMATION ––>
<input type="button" class="create" name="ganntSetup2" value="Setup Gannt2" onClick="google.script.run.runSetup()"/>

<div>
<p></p>
<p></p>
<input type="button" name="Main Menu" value="Main Menu" onClick="google.script.run.mainSidebar()" />
</div>

</div>

<div style=
"width: 100%;
position: fixed;
bottom: 0;
width: 100%;
text-align:center;
background-color:black;
text-color:white;">
<p><a href="http://www.fastadmin.solutions" target="blank"><b>©FastAdmin Solutions</b></a></p>
</div>
</div>
<script>

function runSetup(projectTitle,projectMgr,projectSponsor,datepicker,weeks) {
//function runSetup() {
console.log("before the vars");
//Logger.log("before the vars");
var ptitle = projectTitle;
var pMan = projectMgr;
var pSpon = projectSponsor;
var date = datepicker;
var wks = weeks;
var tHeader = "Project";
var mHeader = "Project Manager";
var sHeader = "Project Sponsor";
//Logger.log("yeeHa");
console.log("yeeHa");
}
</script>
</body>
</html>

关于javascript - 当包含参数时,函数调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51448328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com