Javascript函数只能以不同的名称调用
javascript function gets called only with a different name
当我试图调用javascript文件中的方法时,我有一个奇怪的问题。这个.js文件有以下两个方法:
function setCookie(c_name, value, exdays)
{
//set the expiry date as now + the specified number of days
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
//add the expiry date string to the cookie value
var c_value = escape(value) + ((exdays==null) ? "" : ";
expires="+exdate.toUTCString()+"; path=/");
//set the cookie
document.cookie = c_name + "=" + c_value;
}
function setTheCookie(c_name, value, exdays)
{
//set the expiry date as now + the specified number of days
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
//add the expiry date string to the cookie value
var c_value = escape(value) + ((exdays==null) ? "" : ";
expires="+exdate.toUTCString()+"; path=/");
//set the cookie
document.cookie = c_name + "=" + c_value;
}
当我使用onclick="setTheCookie('cookie_bar_hide', 'yes', 365)"
时,它被调用,但当我使用onclick="setCookie('cookie_bar_hide', 'yes', 365)"
时,它没有被调用。
你知道为什么会这样吗?
设置setCookie
从控制台
> setCookie
function setCookie(name, value)
{
document.cookie = escape($.trim(name)) + '=' + escape(value) + ';path=/';
}
查看所有JavaScript文件,setCookie
位于您的base.js
和cookie.js
中。
我认为这可能与您如何调用onClick事件上的函数有关。像这样调用多个方法:
onClick="doSomething();doSomethingElse();"
没有多个OnClick。
让我知道这是否解决了问题。
相关文章:
- 如何从模块链中调用函数.导出到节点中
- 调用函数内部的函数
- 在javascript中调用c函数
- DropDownListFor赢得't在更改时调用函数
- Javascript页面调用函数
- 在动画结束之前调用函数
- 允许父窗口在其不同域的子iframe上调用函数
- 运行Infinite Scroll后调用函数时出现问题
- JavaScript:在调用函数的文本输入上按enter键
- 使用大括号和不使用bracs调用函数的区别
- javascript在事件上调用函数
- 从index.html调用函数,该函数无限循环
- 从带参数的字符串变量调用函数中的函数
- 为什么 JS 不在滚动时调用函数
- 是否可以在不更改上下文的情况下调用函数.apply
- 如何在ES6类中使用参数调用函数
- AngularJS:调用函数时编号不更新
- JavaScript中的立即调用函数表达式(IIFE)-传递jQuery
- 在JavaScript中调用函数时自定义此选项
- 调用函数中声明的变量