最近研究了下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);

}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐