$(document).ready(function(){
// 开始写 jQuery 代码...
});
$(function(){
// 开始写 jQuery 代码...
});
$("p")
$("#id")
$('.class')
$(this)
$('p#id')
显示隐藏
.hide
.show
.toggle
淡入淡出
.fadeIn
.fadeOut
.fadeToggle
滑动
.slideDown
.slideUp
.slideToggle
动画
.animate
.stop
DOM操作
.text
.html
.val
获取属性
.attr("href")
.prop
添加
元素内
.append
.prepend
元素外
.after
.before
删除元素
.remove(".需要指定的元素")
.empty("子元素")
操作css
.addClass()
.removeClass()
.toggleClass()
.css({"background-color":"yellow","font-size":"200%"});
尺寸
.width
.height
.innerWidth
.innerHeight
.outerWidth
.outerHeight
遍历
.parent 直接父元素
.parents 所有祖先元素
$("span").parentsUntil("div"); 两个给定元素之间
.children 直接子元素
.find
.siblings 所有同胞元素
.next 下面
.nextAll
.nextUntil
.prev 上面
.prevAll
.prevUntil
.first
.last
.eq(下标)
.filter
.not
.load
.get
.post
$.noConflict()
$.getJSON
document.getElementById()
document.getElementsByTagName()
document.getElementsByClassName()
.innerHTML
.innerText textContent
.appendChild
.insertBefore
.removeChild
.value
.checked
.radio
获取url路径
location.pathname
当捕捉到事件(event)时,做某些判断,如果判断失败,则阻止当前事件继续运行
window.event.returnValue=false
jQuery获取未选中的checkbox
$('input[type=checkbox]').not("input:checked");
jQuery获取选中的checkbox
$('input[type=checkbox]:checked');
jquery判断checked的三种方法
.attr('checked'): //看版本1.6+返回:"checked"或"undefined" ;1.5-返回:true或false
.prop('checked'): //16+:true/false
.is(':checked'): //所有版本:true/false//别忘记冒号哦
javascript和jquery如何获取当前页面的url(http://abshu.com/show.php?id=39)
Javascript:
代码 返回
--------------------------------------------------------------------------
window.location.host www.abshu.com:8082
window.location.hostname www.abshu.com
window.location.port 8082
window.location.protocol http
window.location.pathname index.php
window.location.href http://www.abshu.com:8082/index.php#tab2
window.location.hash #tab2
window.location.search ?foo=123
Jquery:
代码 返回
--------------------------------------------------------------------------
$(location).attr('host'); www.test.com:8082
$(location).attr('hostname'); www.test.com
$(location).attr('port'); 8082
$(location).attr('protocol'); http
$(location).attr('pathname'); index.php
$(location).attr('href'); http://www.test.com:8082/index.php#tab2
$(location).attr('hash'); #tab2
$(location).attr('search'); ?foo=123
获取form(有id)中input(没有id) 的值,如:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
</head>
<body>
<form id="haha">
<input type="text" name="heihei" value="test2"/>
</form>
<script>
var aaa = $("#haha").find("input").val();
alert(aaa);
</script>
</body>
</html>
弹框显示
test2
网友评论