Javascript函数只能以不同的名称调用

javascript function gets called only with a different name

本文关键字:调用 函数 Javascript      更新时间:2023-09-26

当我试图调用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.jscookie.js中。

我认为这可能与您如何调用onClick事件上的函数有关。像这样调用多个方法:

  onClick="doSomething();doSomethingElse();"

没有多个OnClick。

让我知道这是否解决了问题。