只能使用不同的名称调用javascript函数

只能使用不同的名称调用javascript函数,javascript,asp.net,Javascript,Asp.net,我在尝试调用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

我在尝试调用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\u bar\u hide','yes',365)”
时,单击按钮会调用它,但当我使用
onclick=“setCookie('cookie\u hide','yes',365)”
时不会调用它


知道为什么会发生这种情况吗?

我相信这可能与您在onClick事件中调用函数的方式有关。调用多种方法,如下所示:

  onClick="doSomething();doSomethingElse();"
不适用于多个OnClick


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

设置setCookie时还有其他问题

从控制台

> setCookie
function setCookie(name, value)
{
    document.cookie = escape($.trim(name)) + '=' + escape(value) + ';path=/';
}

查看所有JavaScript文件,
setCookie
位于
base.js
cookie.js

什么是
console.log(setCookie.toString())返回?单击此
返回的整个元素的确切代码是什么?您在哪个浏览器中测试?您尝试过调试吗?可以在此屏幕上看到完整的代码。就在身体标签之后,我有了cookies条形码。谢谢你发现了这个问题。如果两个.js文件中存在同名函数,那么哪个函数优先,并且不取决于传入的参数数量?不,JavaScript中没有重载。第二名的优先于前一名。