我正在編寫一個谷歌應用程序腳本網站/項目的時刻,我面臨一個問題,我的HTML文件調用JavaScript函數。Javascript中的多個函數
我有一個函數,當我點擊不同的按鈕時,它使用DOM操作來更改divs內容。
但是,如果我想在我的<script>
元素中添加另一個函數(它甚至不需要對我的第一個函數做些什麼),並且運行該應用程序,第一個函數根本不起作用,我點擊一個按鈕。
<?!= include('CSS'); ?>
<body>
<div id="header">
<h1>Auction System Software Engineering1</h1>
</div>
<div id="nav">
<button class="myButton" id="registration"
onclick="changeCenter('regForm')"> Registration </button><br>
<button class="myButton" id="searchItem"
onclick="changeCenter('search')"> Search Items </button><br>
<div id="logIn"> <?var url = getScriptUrl();?>
<form id="loginform" action='<?=url?>?page=LoggedIn' target='_top'>
username: <input type="text" name="username"/><br>
password:
<input type="password" name="password"/>
<input type="submit" id="loginBtn" value="Login"/>
</form>
</div>
</div>
<div id="section">
<div id="regForm" style="display:none">
<form id="myForm">
<fieldset>
First name: <input name="prename" type="text" /> <br>
Second name: <input name="surname" type="text" /> <br>
birthday: <input name="bday" type="text" /> <br>
adress: <input name="adress" type="text" /> <br>
username: <input name="unameReg" type="text" /> <br>
password: <input name="pwReg" type="password" /> <br>
repeat password: <input name="pwReg2" type="password" /> <br>
<input type="button" value="Submit" />
</fieldset>
</form>
</div>
這是HTML佈局
<script>
// this is the function to change html parts dynamically, like f.e. when
clicking a registration button, the welcome center section dissapears
and the registration form will be activated
function changeCenter(divID){
//Hide the currently shown element first
if(document.getElementById("Welcome").style.display == 'block'){
document.getElementById("Welcome").style.display = 'none';
}
else if (document.getElementById("search").style.display == 'block'){
document.getElementById("search").style.display = 'none';
}
else if (document.getElementById("regForm").style.display == 'block'){
document.getElementById("regForm").style.display = 'none';
}
//display the element that will be shown. No content is injected yet
document.getElementById(divID).style.display = 'block';
}
function testingXY{
}
</script>
如果我刪除功能testingXY它會工作,我可以再次更改中心,而是當它添加它不會工作。希望這段代碼現在能幫助你。
return HtmlService.createTemplateFromFile('Main').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
這就是應用程序的腳本程序打開後,將要執行我的.GS代碼行(槽的doGet(E)方法)
所以,你已經證明代碼的工作,甚至沒有顯示我的猜測是如何'changeCentre'執行......是,你所遇到的問題是在你的代碼還沒有表現出 –
是的,請顯示你做了什麼讓代碼無法正常工作。 – forgivenson
@JaromandaX它現在更新了 –