jquery


js table to csv

$.fn.tableToCSV = function(filename) {
        var csv_str = "";
        function createCSVRow(data) {
            var row = "";
            for (var i = 0; i < data.length; i++) {
                var cell = (""+data[i]).replace('"', '""');
                row += ~cell.indexOf(";") ? '"' + cell + '";' :  cell + ";";
            }
            return row.replace(/(;$)/, "");
        }
        function popup(data){
            $("body").append('
'); $("#exportdata").val(data); $("#exportform").submit().remove(); return true; } this.each(function() { $("tr", this).each(function() { var cells = $("td,th", this).map(function() { return $(this).text(); }).get(); csv_str += createCSVRow(cells) + "\n"; }); }); popup(csv_str); //window.location = "data:application/csv;charset=utf=8;base64," + window.btoa(unescape(encodeURIComponent(csv_str))); };

(continue reading…)


Jquery 离开页面时提醒

//绑定beforeunload事件
$(window).bind(‘beforeunload’,function(){
return ‘您输入的内容尚未保存,确定离开此页面吗?’;
});

//解除绑定,一般放在提交触发事件中
$(window).unbind(‘beforeunload’);


jQuery实现图片延迟加载

在浏览有些网站时,发现图片是在下拉滚动条时才加载,这是一个很不错的用户体验。这一效果是通过JavaScript 编写的 jQuery 插件实现的,它可以延迟加载长页面中的图片. 在浏览器可视区域外的图片不会被载入, 直到用户将页面滚动到它们所在的位置. 这与图片预加载的处理方式正好是相反的.在包含很多大图片长页面中延迟加载图片可以加快页面加载速度. 浏览器将会在加载可见图片之后即进入就绪状态. 在某些情况下还可以帮助降低服务器负担. 有些WordPress主题也具备了此功能。

(continue reading…)


JQuery trim()用法

$.each(ob,function(k,val){
       if(k=='cname'){
                    var s = $.trim(ob.cname);
                     $("#nianji").append("<option value='"+s+"'>"+s+"</option>");
       }
  });

这个是全都支持的. $.trim()

“autoresize”插件自动改变textarea大小

The following options are available:

onResize – (type: Function) – A callback function fired every time the textarea is resized. Within the function ‘this’ refers to the textarea being resized.
animate – (type: Boolean) – If set to false no animation will take place, the height will immediately change when necessary. By default it’s set to true.
animateDuration – (type: Number) – Millisecond duration of animation, by default it’s set to 150. (continue reading…)


autoTextarea-文本框根据输入内容自适应高度

CSS代码:
JS代码,默认的参数及调用:
//默认的参数
$(“.chackTextarea-area”).autoTextarea({
maxHeight:220,//文本框是否自动撑高,默认:null,不自动撑高;如果自动撑高必须输入数值,该值作为文本框自动撑高的最大高度
minHeight:$(this).height()//默认最小高度,也就是文本框最初的高度,当内容高度小于这个高度的时候,文本以这个高度显示
}) (continue reading…)


jquery 新建的元素事件绑定问题

js的事件监听跟css不一样,css只要设定好了样式,不论是原来就有的还是新添加的,都有一样的表现。而事件监听不是,你必须给每一个元素单独绑定事件。

常见的例子是处理表格的时候。每行行末有个删除按钮,点了这个能够删除这一行。 (continue reading…)


jQuery live() failing with jQuery UI datepicker

I’ve got it to bind to the lightbox’d inputs on the first appearance of the lightbox, but it’s not working afterwards.

I’m doing the following:

$(function() { 
    $('.jQueryCalendar').live('click', function () {
            $(this).datepicker({showOn: 'both'}).focus();
    });
});

When the lightbox closes, I’m re-appending it’s content to the page (in order to not lose the content div), and this seems to be killing the live() call. [NB the re-appending takes place after the original content is destroyed]

EDIT

Ok, the live() event IS firing (thanks to Nick Craver for that), however the datepicker is no longer being shown. Does anyone have an idea why?

EDIT #2

Ok, the use of .html() to re-append causes the events to need rebinding, but the element to bind still has the class hasDatepicker, which messes with the datepicker() initialisation.

To fix, simply user

$(this).removeClass('hasDatepicker') .datepicker({showOn: 'both'}).focus();

 


jQuery.Autocomplete 中文支持

jQuery.Autocomplete是jquery的流行插件,能够很好的实现输入框的自动完成(autocomplete)、建议提示(input suggest)功能,支持ajax数据加载。 (continue reading…)


Copyright © 1996-2010 Add Lives. All rights reserved.
iDream theme by Templates Next | Powered by WordPress