获取或设置当前标签的属性:
$(this).attr(key); 获取节点属性名的值,相当于getAttribute(key)方法
$(this).attr(key, value); 设置节点属性的值,相当于setAttribute(key,value)方法
$(this).val();获取某个元素节点的value值,相当于$(this).attr(“value”);
$(this).val(value);设置某个元素节点的value值,相当于$(this).attr(“value”,value);
改变href属性的链接:
<a id="test">test</a>
<a href="#" onclick="document.all.test.href='#';">去除</a>
<a href="#" onclick="document.all.test.href='http://www.google.com';">增加</a>
改变带点击事件的属性:
$("a").live("click", function (event) {
jQuery(this).attr("href","");
});
移除点击属性:
obj.removeAttribute(" or obj.onclick="";
jquery的ubind方法来解除click绑定:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script src="js/jquery-1.3.2.min.js"></script> </head> <body> <img id="img1" src="1/a.jpg" width="80" height="35" /> <input id="cancelEvent" type="button" value="取消事件" /> </body> </html> <script language="javascript"> $(function () { $('#img1').click(test); $('#cancelEvent').click(function() { $("#img1").unbind("click"); }); }); function test() { alert("test()"); } </script>
离开页面时的触发操作:
<script>
function fnUnloadHandler() {
//```````````````
}
</script>
<body onbeforeunload="fnUnloadHandler()"></body>
离开页面前onbeforeunload事件在火狐的兼容并且提交不触发 :
<html> <head> <script language="javascript"> var thisPage=false; window.onbeforeunload=function checkLeave(e){ var evt = e ? e : (window.event ? window.event : null); //此方法为了在firefox中的兼容 if(!thisPage)evt.returnValue='离开会使编写的内容丢失。'; } function sumbit(){ thisPage=true; document.getElementById('YourFormId').submit(); } </script> </head> <body> <p><a href='http://www.baidu.com'>baidu.com</a></p> <form id='YourFormId' action='http://www.baidu.com'> <input type="button" name="button" id="button" value="提交" </form> </body> </html>
jQuery easy ui中comboTree知识:
1.选择树中的某一节点,但是不会写到文本框中,只在下拉列表中处于选择状态
var node=$('#liveChannelId').combotree('tree').tree('find',id);
$('#liveChannelId').combotree('tree').tree('select',node.target);
$('#liveChannelId').combotree('tree').tree('expandAll', node.target);
2.选择某一节点并写到文本框中, id一定要在树中存在
$('#liveChannelId').combotree('setValue', id);// 参数是id 非text
3.设定只有子节点可选
function hideTopTVSelect(){ var nodeids = $("div[node-id]"); for(var i=0;i<nodeids.length;i++){ if($(nodeids[i]).attr("node-id")==0){ var node = $(nodeids[i]); node.unbind("click"); node.bind("click",function (){ $($(this).children()[0]).click(); var maxht = $(window).height(); var ht = $(this).parent().parent().height(); if(ht<maxht) maxht=ht; $(this).parent().parent().parent().height(maxht); }); } } }
禁用、启用<input>标签
document.getElementById("removeButton").disabled = false;//普通Js写法
$("#removeButton").removeAttr("disabled");//要变成Enable,JQuery只能这么写
$("#removeButton").attr("disabled","disabled");//再改成disabled
<a>标签 http://www.cnblogs.com/beiguren/archive/2010/05/24/1742926.html