$(".tab_ul li").click(function () {
$('.tab_ul li').index(this); //获取当前的点击
});
关于event="click.*"
<a event="click.sendmsg" href="javascript:;">发私信</a>
var a = $('.colMain a');
a.filter('[event="click.sendmsg"]').click(function () {
var _this = $(this).parent();
// code
});
ajax data提交
data: "qid=val&"+Math.random()
您还可以输入*个字
$('#overview').bind('keyup',function(){
var _val = $(this).val();
var len = 200;
if ( _val == $(this).attr('tip') || !_val)
{
$('#TT-len-info').html('还可输'+len+'字');
return;
} var _n = parseInt(len)-_val.length;
if (_n<0)
{
$(this).val(_val.substr(0,len));
}
else
{
$('#TT-len-info').html('还可输'+_n+'字');
}
});
jquery获取复选框的值
var chk_value =[]; $('input[name="test"]:checked').each(function(){ chk_value.push($(this).val()); });
使用 jquery 获取当前时间的方法
<html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> <script type="text/javascript">function currentTime(){ var d = new Date(),str = ''; str += d.getFullYear()+'年'; str += d.getMonth() + 1+'月'; str += d.getDate()+'日'; str += d.getHours()+'时'; str += d.getMinutes()+'分'; str+= d.getSeconds()+'秒'; return str; } setInterval(function(){$('#time').html(currentTime)},1000); </script> </head> <body> <div id="time"></div> </body> </html>
数组技巧
把数据结合成字符串 var str = ['a', 'b', 'c'].join(''); 结果:abc var arr = 'abc'.split(''); 结果:['a', 'b', 'c']
//字符串转为数组
if (type.indexOf(',') >= 0) { $.each(type.split(','), function(i,v) { }); return; }
//添加插件
var _plugins = {}; function _plugin(name, fn) { if (name === undefined) { return _plugins; } if (!fn) { return _plugins[name]; } _plugins[name] = fn; } 使用 obj.plugin = _plugin; obj.plugin('wordpaste', function(p) {})