jquery 应该注意的几件事情

1.change事件只能限制在input类型、textarea、select类型(包括了单选 select、复选框checkbox、单选框radio)

select类型(包括了单选 select、复选框checkbox、单选框radio)当value值改变的时候会立即出发change事件、而其他元素只有当失去焦点的时候才会出发change事件。

以下是官方说明

The change event is sent to an element when its value changes. This event is limited to <input>elements, <textarea> boxes and <select> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.

2.height()、.css('height')、.innerHeight()、.outerHeight()区别

首先.height()、.css('height')区别 二者的主要区别是后者返回的是带精确单位的如400px、而前者是不带的如400所以前者更适合数学计算

height().innerHeight()、.outerHeight() 这几个的主要区别是看图

.height()innerHeight()outerHeight()

 


触类旁通 宽度的就不再说明了

 

3. 。select() select事件只限制在文本框和文本域两个元素使用,

以下是官方原文

The select event is sent to an element when the user makes a text selection inside it. This event is limited to <input type="text"> fields and <textarea> boxes.

4. jquer1.4新增方法detach()

 

detach相对remove来说是指你要删除的jquery对象,如果把这些jquery对象插入新的dom中的话 其上bind的事件还会存在,

作用相当与$(selector).clone(true).appendTo(selector1).next().next().remove();=$(selector).detach().appendTo(selector1)

 

显然后者更简洁一点

 

5. wrap() 与 wrapAll()的区别

wrap("div")方法会为每一个匹配的元素单独添加一个父div,wrapAll(“div”) 则是为匹配的元素添加一个公共的父div

如下

 

<p>one</p>
<p>two</p>
<p>three</p>

 

使用$("p").wrap("div")则结果是

 

<div><p>one</p></div>
<div><p>two</p></div>
<div><p>three</p></div>

 

 

使用$("p").wrapAll("div");则结果是

 

<div>
<p>one</p>
<p>two</p>
<p>three</p>
</div>

 

6.get()方法

当$(selector).get()方法无参数的时候返回的是全部数据一个数组,当$(selector).get("-1") 当参数为负数的时候返回的是集合中最后一个,从后面算。

 

7. jQuery.extend() 、 jQuery.fn.extend()、jQuery.fn.interval=100(1.4新增) jQuery.fn.off(1.3新增)

jQuery.extend() 扩展的是jQuery对象,调用时得通过 $.funcName()调用

jQuery.fn.extend()扩展的是jQuery 元素集 调用时得通过$(selector).funcName()调用

jQuery.fn.interval 设置时jQuery动画l在一毫秒播放的帧数

jQuery.fn.off关闭jQuery动画

 

8.火狐下jquery代码失效的问题

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
    <script src="http://code.jquery.com/jquery-1.4.4.js" charset="utf-8"></script>
	<script type="text/javascript">
	 $(function(){
	    //alert("------------");
		$("#file").bind("change",function(){alert($("#file").val())
			$("#file").val("失效的地方")
			alert("赋值ok");
			})
		$("#file2").val("223sdssssssssssssssdf")
		alert("---------sdfs---");
		})
	</script>
</head>
<body>
     <div> 
     	<input type="file" class="focus" value="cccccccccccc" id="file" />
     	<input type="text" class="focus" id="file2" />
     </div>
     <div id="new"> 
     	
     </div>
  </body>
</html>

 $("#file").val("失效的地方") ,在火狐浏览器如果向file上传文件框 赋值的时候那么alert("赋值ok");不会被弹出 ,

但是赋值为空是可以的如$("#file").val("");

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值