使用jQuery插件时,TypeError $(...)不是函数 [英] TypeError $(...) is not a function when using a jquery plugin

查看:118
本文介绍了使用jQuery插件时,TypeError $(...)不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Jquery专家准备了一个.

I got one for the Jquery experts.

我下载了一个简单的jquery插件,可以将Table转换为CSV.

I downloaded a simple jquery plugin to convert from Table to CSV.

这是源代码... http://www.kunalbabre.com/projects/table2CSV.js

现在,我创建了一个本地jscript文件. jquery.Table2CSV.js.我在jquery之后立即添加到页面中

Now, I created a local jscript file. jquery.Table2CSV.js. I added to my page right after my jquery

<script type="text/javascript" src='@Url.Content("~/Scripts/libs/jquery-1.6.3.min.js")'></script>
<script type="text/javascript" src='@Url.Content("~/Scripts/jquery.Table2CSV.js")'></script>

根据Firebug,它加载正确(200 OK).

It's loading correct (200 OK) according to Firebug.

在我的一种观点中,我有以下代码...

In one of my views, i have the following code...

<script>
    $(document).ready(function () {
        $("#exportToCSV").click(function (event) {

            event.preventDefault();
            alert('button clicked!');
            $('#reportDataTable').table2CSV();
        });
    });
</script>

触发器触发click事件,没问题,但是出现以下错误.

The trigger fires the click event, no problem, but i get the following error.

TypeError:$(...).table2CSV不是函数

TypeError: $(...).table2CSV is not a function

(?)(事件=对象{originalEvent =事件点击,键入="click",timeStamp = 88685109,更多...})摘要(第109行) add(c = Object {originalEvent = Event click,type ="click",timeStamp = 88685109,more ...})资产.... zogAQAA(第3行) add(a = click clientX = 849,clientY = 231)asset .... zogAQAA(第3行) [解决此错误]

(?)(event=Object { originalEvent=Event click, type="click", timeStamp=88685109, more...})summary (line 109) add(c=Object { originalEvent=Event click, type="click", timeStamp=88685109, more...})asset....zogAQAA (line 3) add(a=click clientX=849, clientY=231)asset....zogAQAA (line 3) [Break On This Error]

$('#reportDataTable').table2CSV();

$('#reportDataTable').table2CSV();

我试图在这里找到有意义的东西,但到目前为止还没有解决方案.

I tried to find something meaningful here but no solution so far.

有人可以帮助我了解这里发生的事情吗?

Can anyone help me understand what's going on here?

谢谢.

这是插件的源代码.

jQuery.fn.table2CSV = function(options) {
    var options = jQuery.extend({
        separator: ',',
        header: [],
        delivery: 'popup' // popup, value
    },
    options);

    var csvData = [];
    var headerArr = [];
    var el = this;

    //header
    var numCols = options.header.length;
    var tmpRow = []; // construct header avalible array

    if (numCols > 0) {
        for (var i = 0; i < numCols; i++) {
            tmpRow[tmpRow.length] = formatData(options.header[i]);
        }
    } else {
        $(el).filter(':visible').find('th').each(function() {
            if ($(this).css('display') != 'none') tmpRow[tmpRow.length] = formatData($(this).html());
        });
    }

    row2CSV(tmpRow);

    // actual data
    $(el).find('tr').each(function() {
        var tmpRow = [];
        $(this).filter(':visible').find('td').each(function() {
            if ($(this).css('display') != 'none') tmpRow[tmpRow.length] = formatData($(this).html());
        });
        row2CSV(tmpRow);
    });
    if (options.delivery == 'popup') {
        var mydata = csvData.join('\n');
        return popup(mydata);
    } else {
        var mydata = csvData.join('\n');
        return mydata;
    }

    function row2CSV(tmpRow) {
        var tmp = tmpRow.join('') // to remove any blank rows
        // alert(tmp);
        if (tmpRow.length > 0 && tmp != '') {
            var mystr = tmpRow.join(options.separator);
            csvData[csvData.length] = mystr;
        }
    }
    function formatData(input) {
        // replace " with “
        var regexp = new RegExp(/["]/g);
        var output = input.replace(regexp, "“");
        //HTML
        var regexp = new RegExp(/\<[^\<]+\>/g);
        var output = output.replace(regexp, "");
        if (output == "") return '';
        return '"' + output + '"';
    }
    function popup(data) {
        var generator = window.open('', 'csv', 'height=400,width=600');
        generator.document.write('<html><head><title>CSV</title>');
        generator.document.write('</head><body >');
        generator.document.write('<textArea cols=70 rows=15 wrap="off" >');
        generator.document.write(data);
        generator.document.write('</textArea>');
        generator.document.write('</body></html>');
        generator.document.close();
        return true;
    }
};

好的.新编辑 在我脚本的结尾,我从特里里克先生那里得到了这个东西.

Ok. New EDIT At the end of my scripts, I had this from Mr. Telerik...

@(Html.Telerik().ScriptRegistrar().DefaultGroup(group => group.Combined(true).Compress(true)))

我删除了它,效果很好.你一个小问题.现在,我来自Telerik的jqueries无法正常工作....同时,我正在做一些有关如何使此人与我的jqueries共存的研究.

I removed it and it worked just fine. One little problem thou. Now my jqueries from Telerik don't work.... I am doing some research in the meantime on how to make this guy to coexist with my jqueries.

推荐答案

已解决....这是解决方案.

Solved.... Here is the solution.

http://www.telerik.com/community/forums/aspnet-mvc/general/telerik-doesn-t-let-me-work-with-jquery-ui.aspx

我希望它对以后的人们有所帮助.

I hope it helps people in the future.

基本上,这种Telerik自己的jquery文件注册似乎还添加了jquery(双重注册).

Basically, seems like this telerik registration of their own jquery files also adds jquery (double registration).

谢谢

这篇关于使用jQuery插件时,TypeError $(...)不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆