简体   繁体   中英

js,jquery,easyui, the param changed when passed to the function

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);
}

I passed a param "2014-05-22" to showChar_org(vstday) but finally the vstday was 1987.That is a strange.The chrome console printed as follows:

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 

But when I change the "2014-05-22" to "2014-05-21", the result is 1988. when I change the "2014-05-22" to "2014-05-01", the result is 2008.why? When I add double quotes("") to the "2014-05-22" string, the result is OK. the code as folllows:

 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>';

The chrome console printed as follows:

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

any help would be appreciate.

When you pass showChart_org(2014-05-20) , its actually evaluating the date which is just number.

2014 - 05 = 2009

2009 - 20 = 1989

That's the reason why 2014-05-22 returns you 1987.

So you need to pass it as string to ignore that :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM