【问题标题】:js,jquery,easyui, the param changed when passed to the functionjs,jquery,easyui, 传递给函数时参数改变
【发布时间】:2014-05-24 15:50:35
【问题描述】:
function formatData_org() {
    // convert
    obj_num2.formatter = function(value, rec) {
        var baseStr='  '
                + rec.s_date + '<a  class="easyui-linkbutton"     href="javascript:void(0);" plain="true" iconCls="icon-statistic" onclick=showChart_org('+"2014-05-22"+ ')></a>';
        console.log("baseStr: " + baseStr);
        return '<div id="toolbar">'+baseStr+'</div>';

};

function showChart_org(vstday){
       console.log("vstday: " + vstday);
}

我将参数“2014-05-22”传递给 showChar_org(vstday) 但最后 vstday 是 1987 年。这很奇怪。chrome 控制台打印如下:

baseStr: &nbsp;&nbsp;2014-05-22<a  class="easyui-linkbutton" href="javascript:void(0);" 
plain="true" iconCls="icon-statistic" onclick=showChart_org(2014-05-22)></a>
vstday: 1987 

但是当我将“2014-05-22”更改为“2014-05-21”时,结果是 1988。 当我将“2014-05-22”更改为“2014-05-01”时,结果是 2008。为什么? 当我将双引号(“”)添加到“2014-05-22”字符串时,结果是好的。代码如下:

 var baseStr='&nbsp;&nbsp;'+ rec.s_date + '<a  class="easyui-linkbutton"href="javascript:void(0);" plain="true" iconCls="icon-statistic" onclick=showChart_org("'+"2014-05-22"+ '")></a>';

chrome控制台打印如下:

baseStr: &nbsp;&nbsp;2014-05-22<a  class="easyui-linkbutton" href="javascript:void(0);"plain="true" iconCls="icon-statistic" onclick=showChart_org("2014-05-22")></a> 
vstday: 2014-05-22

任何帮助将不胜感激。

【问题讨论】:

  • 它正在评估参数 (2014-05-22),即 2014 减去 05 减去 22,因此将其作为 1987 发送到函数
  • 非常感谢,您给了我很大的帮助。

标签: javascript jquery jquery-easyui


【解决方案1】:

当您通过 showChart_org(2014-05-20) 时,它实际上评估的日期只是数字。

2014 - 05 = 2009

2009 - 20 = 1989

这就是 2014-05-22 为您返回 1987 的原因。

所以你需要将它作为字符串传递以忽略它:)

【讨论】:

  • 哦,我知道了。哈哈,非常感谢。 @Rory McCrossan
猜你喜欢
  • 2013-08-08
  • 1970-01-01
  • 2013-01-27
  • 2010-09-27
  • 1970-01-01
  • 2021-08-28
  • 2014-08-16
  • 1970-01-01
  • 2011-04-16
相关资源
最近更新 更多