首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

jquery 应当注意的几件事情

2012-10-30 
jquery 应该注意的几件事情1.change事件只能限制在input类型、textarea、select类型(包括了单选 select、复选

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() 这几个的主要区别是看图

jquery 应当注意的几件事情jquery 应当注意的几件事情jquery 应当注意的几件事情

?


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

?

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" value="cccccccccccc" id="file" />     <input type="text" id="file2" />     </div>     <div id="new">           </div>  </body></html>

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

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

?

?

热点排行