js和jQuery的常用功能

来源:互联网 发布:知乎日报rss 编辑:程序博客网 时间:2024/05/21 07:08

js的添加属性和移除属性

添加:document.getElementById(“down”).setAttribute(“disabled”,true);

移除:document.getElementById(“up”).removeAttribute(‘disabled’);

jq的添加属性和移除属性

添加:$(“#up”).attr(“disabled”,true);

移除:$(“#down”).removeAttr(“disabled”);

js控制css的单个和多个样式

document.getElementById(“down”).style.borderColor=”#61AED0”;

document.getElementById(“down”).style.backgroundColor=”#61AED0”;

jq控制css的单个和多个样式

单个:$(“#down”).css(“backgroundColor”,”#61AED0”);

多个:$(“#down”).css({background:”#61AED0”,borderColor:”#61AED0”});

jq查找元素

$(“:input[name=’search’]”).val();

$(obj).parent().find(“[name=’search’]”).val();

js&&jq的div的创建

js的div创建

document.createElement(“div”)

jq的div创建

(<div></div>).appendTo((“body”));

js的获取焦点和失去焦点

onfocus()和onBlur()

jq的获取焦点和失去焦点

blur()和focus()

js&&jq的获取宽高

js获取当前页面的宽度&&高度
document.documentElement.clientWidth

document.documentElement.clientHeight

jq获取当前页面的宽度&&高度
$(window).width()

$(window).height()

js获取div宽度&&高度
showBox.offsetWidth

showBox.offsetHeight

jq获取div宽度&&高度
$(showBox).outerHeight()

$(showBox).outerWidth()

js获取文档的宽度&&高度
document.body.scrollHeight

document.body.scrollWidth

jq获取文档的宽度&&高度
$(document).height()

$(document).width()

outerWidth()方法用于获得包括内边界(padding)和边框(border)的元素宽度,如果outerWidth()方法的参数为true则外边界(margin)也会被包括进来

innerWidth()方法用于获得包括内边界(padding)的元素宽度

js的显示和隐藏

msg.style.display=”block”;

label.style.display=”none”;

jq的显示和隐藏

$(“#msgBox”).show();

$(obj).siblings().hide();

js’的编辑内容

document.getElementById(“infot”).innerHTML=info;

jq的编辑内容

$(“#infot”).html(info);

原创粉丝点击