[英]javascript function only works with the first included function
I have the following function ( onButtonClick
) when the button is clicked only the first function works. 单击按钮时,只有以下第一个功能有效,我具有以下功能(
onButtonClick
)。 All the included functions work if I only have one of them in the button function. 如果按钮功能中只有其中一个功能,则所有包含的功能都可以使用。
I have also tried the on button click function this way as well. 我也尝试过按此方式单击按钮。 Still does not work.
仍然无法正常工作。
setProjectData() && getProjectData() && window.location.href='support_page.html';
Any ideas on what I may be missing? 关于我可能会缺少的任何想法?
<span class="profile_container_right">
<a onclick='onButtonClick()'; return true;"; ><img src="images/bSUPPORT.png"/></a>
</span>
<script>
/* on button click */
function onButtonClick(){
setProjectData();
getProjectData();
window.location.href='support_page.html';
}
function setProjectData() {
// --- set local storage project descriptions ---
vProjectName=‘The Project Name’;
localStorage.setItem('xProjectName', vProjectName);
return true;
}
function getProjectData() {
// --- get local storage project descriptions ---
vProjectName = localStorage.getItem('xProjectName');
alert('you entered the GET project data function ='+vProjectName);
return true;
}
</script>
First issue is the use of quotes in the onclick binding: 第一个问题是在onclick绑定中使用引号:
onclick='onButtonClick()'; return true;";
The correct syntax for onclick is onclick="yourFunctionCall();"
onclick的正确语法是
onclick="yourFunctionCall();"
for example: 例如:
onclick="onButtonClick(); return true;"
Second issue is your use of quotes in the setProjectData function: 第二个问题是您在setProjectData函数中使用引号:
vProjectName=‘The Project Name’;
Change to single quotes or double quotes: 更改为单引号或双引号:
vProjectName="The Project Name";
With these syntax issues fixed your code should execute as expected. 解决了这些语法问题后,您的代码应按预期执行。
Side note use var
to declare variables within a function to make them adhere to the scope of the function. 旁注使用
var
在函数中声明变量,以使它们遵守函数的范围。 Declaring a js variable without the var
exposes the variable globally. 声明不带
var
的js变量会全局公开该变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.