jquery数据返回" undefined不是函数"当数据值是一个数字

时间:2014-08-14 08:25:09

标签: javascript jquery integer undefined

我刚刚发现,如果data()的值是一个数字,我在尝试调用它时会得到“未定义不是函数”。我在做:

$path = $('td#folder-'+sfx+' a').data('name');

然后将$ path放入ajax请求的数据中,如

 path : $path,

data('name')的值是任何整数(1,2,2335343,无论如何)时,我得到“未定义不是函数”。如果我将值重命名为字符串(例如,9ER),我没有问题。

为什么这是我能做些什么呢?

已更新

根据要求,以下是大部分代码:

             $(proceed).on('click', function(ev){
                    ev.preventDefault();
                    proceed.fadeOut(500);
                    canceldel.fadeOut(500);
                    confirms.fadeOut(500);                  
                    rename.fadeIn(1000);
                    del.fadeIn(1000);       
                    $subdir = $('td#folder-'+sfx+' a').data('name');
                    $path1 = $bm;
                    $path2 = $subdir;
                    if($path1.indexOf('..') >= 0 || $path1 === '/' || $path1 === '' || !$path1 || $path1 === 'undefined' || $path1 === undefined){
                        filertify.set({labels:{ok : "OK" }}); filertify.alert('There was an error completing your request. The path to the directory has not been properly defined.');
                    }else if($path2.indexOf('..') >= 0 || $path2 === '/' || $path2 === '' || !$path2 || $path2 === 'undefined' || $path2 === undefined){
                        filertify.set({labels:{ok : "OK" }}); filertify.alert('There was an error completing your request. The path to the directory has not been properly defined.');
                    }else{
                        $.post(
                            SSFA_FM_Ajax.ajaxurl,
                            {
                                action : 'ajax-ssfa-file-manager',
                                dataType : 'html',  
                                act : 'deletedir',
                                status : 'life',
                                path1 : $path1,
                                path2 : $path2,
                                nextNonce : SSFA_FM_Ajax.nextNonce
                            },
                            function(response){ 

如果我将其称为$(element).attr('data-name')我没有收到错误,但我想要data()版本。

0 个答案:

没有答案