JQuery在项目中的简单使用

最近研究了下JQuery,可以做一些简单的js效果出来,比传统的js少写了很多代码
页面加载执行方法
$(document).ready(function()
{
   
//方法体
});

找到一个id是time的td,返回一个JQuery对象
$("td[@id='time']")


$("#clear").click(
function(e)
{
   
//ID为clear的元素的单击事件
});


$("#alertListfrm
input[@type='checkbox'][@checked]").each(function(){
   
//遍历id为alertlistfrm容器下面选中的checkbox,
    //获取checkbox值
   
this.value
});

//id为alertlistfrm容器下面选中的checkbox的个数
$("#alertListfrm
input[@type='checkbox'][@checked]").size()

//id为alertlistfrm容器下面选中的checkbox的序列化对象
$("#alertListfrm
input[@type='checkbox'][@checked]").serialize()

基本的ajax提交
//post提交
//返回参数处理
//aa需要传递的数据
//nodeidsets为aa取的别名,后台可以通过request.getParameter("nodeidsets")获取aa
//data为后台返回的被JQuery封装的xmlhttprequest对象
//在struts中可以返回一个页面里面包含字符串,然后用data.indexof("")判断字符串是否存在来判断处理结果
//如果没有返回对象,则data为空
//参数aa也能为空
jQuery.post("url",
{nodeIdSets:aa}, function(data){
    if(data.indexOf("") != -1)
   
{
        //处理
       
    }
    else
    {
       
//处理
        window.location = url;
    //   
window.location.reload();
        //window.location.href=url;
   
}});
    });
//get提交
    var url =url;
    $.get(url,
function(data)
    {
       
document.getElementById("causelist").innerHTML = data;
    });
   

//css的切换
$("#filterTag").click(function()
    {
       
if($("#filterinput").css("display") != "none")
        {
           
$("#filterinput").hide();
            $(this).find("img").attr("src",
skinPath + "/images/expand/outspread.gif");
        }
        else
   
    {
            $("#filterinput").show();
           
$(this).find("img").attr("src", skinPath + "/images/expand/shrink.gif");
   
    }
    });
   
   
//checkbox的选中与反选
function
check(obj)
{
    (obj.checked)?checkall():discheckall()
}
function
checkall()
{
    $("input[@name='resId']").attr("checked",
true);
}

function discheckall()
{
   
$("input[@name='resId']").attr("checked",false);
}   

posted on 2012-11-09 22:55  Snail_Renie  阅读(1089)  评论(0)    收藏  举报

导航