摘要:
jQuery( html, [ ownerDocument ] )该语法有以下几种用法:用法 1 :创建新的元素语法jQuery(html,[ownerDocument])你可以传递一个手写的 HTML 字符串,或者由某些模板引擎或插件创建的字符串,也可以是通过 AJAX 加载过来的字符串。但是在你创建 input 元素的时会有限制,可以参考第二个示例。当然这个字符串可以包含斜杠 (比如一个图像地址),还有反斜杠。当你创建单个元素时,请使用闭合标签或 XHTML 格式。例如,创建一个 span ,可以用 $("<span/>") 或 $("<sp 阅读全文
随笔分类 - web---JavaScript---jQuery
JQuery中each()的使用方法说明
2013-03-14 00:44 by youxin, 288 阅读, 收藏, 编辑
摘要:
each(callback)以每一个匹配的元素作为上下文来执行一个函数。意味着,每次执行传递进来的函数时,函数中的this关键字都指向一个不同的DOM元素(每次都是一个不同的匹配元素)。而且,在每次执行函数时,都会给函数传递一个表示作为执行环境的元素在匹配的元素集合中所处位置的数字值作为参数(从零开始的整形)。返回 'false' 将停止循环 (就像在普通的循环中使用 'break')。返回 'true' 跳至下一个循环(就像在普通的循环中使用'continue')。而后面的callback 则是回调函数,指示遍历元素的时候应该赋 阅读全文
jquery ajax parseerror
2013-03-07 22:00 by youxin, 543 阅读, 收藏, 编辑
摘要:
一个奇怪的问题:$(function(){ $("form").submit(function(){ var text=$("#search").val(); console.log(text); $.ajax({ url:'translate.php', type:'GET', dataType:'json', data:{search:text}, error:function(textStatus,errorThrown){ con... 阅读全文
jQuery .submit()没响应
2013-03-07 21:18 by youxin, 810 阅读, 收藏, 编辑
摘要:
一个郁闷了好久的错误:<form method="get"><input type="text" name="search" id="search" /><input type="submit" value="submit" id="submit" /></form>$("#submit").submit(function(){alert("hello");return 阅读全文
jquery bind和live区别
2013-03-07 15:05 by youxin, 202 阅读, 收藏, 编辑
摘要:
jQuery 给所有匹配的元素附加一个事件处理函数,即使这个元素是以后再添加进来的也有效。这个方法是基本是的 .bind() 方法的一个变体。使用 .bind() 时,选择器匹配的元素会附加一个事件处理函数,而以后再添加的元素则不会有。为此需要再使用一次 .bind() 才行。比如说<body> <div class="clickme">Click here</div></body>可以给这个元素绑定一个简单的click事件:$('.clickme').bind('click', functio 阅读全文
php insert 空
2013-03-07 14:53 by youxin, 244 阅读, 收藏, 编辑
摘要:
在sql执行这样一段代码:insert into(NULL,'str','');php读取数据库后json编码能得到类似这样的:[{"id":"1","name":"str","value":""}】;在javascript判断value是否存在看是否==‘’即可,但是如果在Phpmyadmin中我们填写了id和name,不填value,则会是这样:[{"id":"1","name": 阅读全文
jquery :last :last-child区别
2013-03-07 14:29 by youxin, 777 阅读, 收藏, 编辑
摘要:
:lastSelects the last matched element.Note that:lastselects a single element by filtering the current jQuery collection and matching the last element within it.Additional Notes:Because:lastis a jQuery extension and not part of the CSS specification, queries using:lastcannot take advantage of the per 阅读全文
转:getElementById引起的jQuery的选择器bug
2013-03-06 19:41 by youxin, 242 阅读, 收藏, 编辑
摘要:
最近在开发时,偶然又发现jQuery一个bug:SCRIPT5007: 无法获取属性“0”的值: 对象为 null 或未定义jquery-1.8.1.js, 行4978 字符4context = Expr.find["ID"]( token.captures[0].replace( rbackslash, "" ), context, xml )[0];只要执行类似$("#test span")这样的,id选择符后还有选择符的代码在IE7下就会报错。跟踪调试发现,问题出在这里:function( id, context, xml ) 阅读全文
转:jQuery数组处理详解(含实例演示)
2013-03-06 00:25 by youxin, 200 阅读, 收藏, 编辑
摘要:
jQuery的数组处理,便捷,功能齐全. 最近的项目中用到的比较多,深感实用,一步到位的封装了很多原生js数组不能企及的功能. 最近时间紧迫,今天抽了些时间回过头来看 jQuery中文文档 中对数组的介绍,顺便对jQuery数组做个总结.温故,知新.强烈建议你打开DEMO演示后再看下面的详解:点此查看DEMO1. $.each(array, [callback]) 遍历[常用]解释:不同于例遍 jQuery 对象的 $.each() 方法,此方法可用于例遍任何对象(不仅仅是数组哦~). 回调函数拥有两个参数:第一个为对象的成员或数组的索引, 第二个为对应变量或内容. 如果需要退出 each 循 阅读全文
jQuery实现侧边栏随窗口滚动
2013-03-04 00:02 by youxin, 574 阅读, 收藏, 编辑
摘要:
$(function() { var $sidebar = $("#sidebar"), $window = $(window), offset = $sidebar.offset(), topPadding = 15; $window.scroll(function() { if ($window.scrollTop() > offset.top) { $sidebar.stop().animate({ mar... 阅读全文
jQuery关闭/显示侧边栏
2013-03-03 23:58 by youxin, 623 阅读, 收藏, 编辑
摘要:
.toggle( handler(eventObject), handler(eventObject) [, handler(eventObject) ] )handler(eventObject)Type:Function()A function to execute every even time the element is clicked.handler(eventObject)Type:Function()A function to execute every odd time the element is clicked.handler(eventObject)Type:Funct 阅读全文
jQuery检测浏览器名称和版本信息
2013-03-03 22:36 by youxin, 299 阅读, 收藏, 编辑
摘要:
在jQuery中,可以通过访问$.browser对象的属性来获取浏览器的相关信息。$.browser对象即jQuery.browser对象,用于处理与浏览器相关的事务,该对象的属性如下:属性名称说明webkit如果是webkit相关的浏览器,则为true,否则为falsemozilla如果是mozilla相关的浏览器,则为true,否则为falsesafari如果是safari浏览器,则为true,否则为falseopera如果是operan浏览器,则为true,否则为falsemsie如果是IE浏览器,则为true,否则为falseversion获取浏览器的版本号下面是一个查看浏览器相关信息 阅读全文
$(document).ready()和window.onload的区别
2013-03-03 22:32 by youxin, 346 阅读, 收藏, 编辑
摘要:
以浏览器装载文档为例,在页面加载完毕后,浏览器会通过JavaScript为DOM元素添加事件。在常规的JavaScript代码中,通常使用window.onload方法,而在jQuery中,使用的是$(document).ready()方法。$(document).ready()方法和window.onload方法有相似的功能,但是在执行时机方面是有区别的。window.onload方法是在网页中所有的元素(包括元素的关联文件)完全加载到浏览器后才执行,即JavaScript此时才可以访问网页中的任何元素。而通过jQuery中的$(document).ready()方法注册的事件处理程序,可以 阅读全文
jquery 手风琴效果
2013-03-03 22:24 by youxin, 231 阅读, 收藏, 编辑
摘要:
代码:<script type="text/javascript">$(document).ready(function(){ $(".accordion h3:first").addClass("active"); $(".accordion p:not(:first)").hide(); $(".accordion h3").click(function(){ $(this).next("p").slideToggle("slow") .s 阅读全文
jquery判断是否滚动到底部
2013-03-02 18:22 by youxin, 3885 阅读, 收藏, 编辑
摘要:
jQuery CSS 操作函数下面列出的这些方法设置或返回元素的 CSS 相关属性。CSS 属性描述css()设置或返回匹配元素的样式属性。height()设置或返回匹配元素的高度。offset()返回第一个匹配元素相对于文档的位置。offsetParent()返回最近的定位祖先元素。position()返回第一个匹配元素相对于父元素的位置。scrollLeft()设置或返回匹配元素相对滚动条左侧的偏移。scrollTop()设置或返回匹配元素相对滚动条顶部的偏移。width()设置或返回匹配元素的宽度。位置offset([coordinates])position()scrollTop([v 阅读全文
Jquery.ajax中dataType不可少
2013-03-01 14:08 by youxin, 464 阅读, 收藏, 编辑
摘要:
官方关于这个参数的解释:dataType(default:Intelligent Guess (xml, json, script, or html))Type:StringThe type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a 阅读全文
ie下ajax错误:由于出现错误 c00ce56e 而导致此项操作无法完成
2013-03-01 14:01 by youxin, 845 阅读, 收藏, 编辑
摘要:
于是打开超级简陋的 IE 调试工具,使用“网络”->“开始捕获”的工具抓取 ajax 请求头,得到 200 的响应头,但是在 jquery 的 ajax 中却是由 error 处理的,200 的结果怎么会跑到 error 去处理呢?于是,在 error 中加入各种调试输出:12345678error: function(XMLHttpRequest, textStatus, errorThrown) {console.log(XMLHttpRequest);console.log('readyState: ' + XMLHttpRequest.readyState);co 阅读全文
JQuery -- this 和 $(this) 的区别
2013-02-28 18:29 by youxin, 215 阅读, 收藏, 编辑
摘要:
this,如果是取得元素的话,则对应当前元素的对象$(this)则是当前元素被jQuery处理的对象。看看作者是怎么写的,来源:http://www.cnblogs.com/RuiLei/archive/2009/08/20/1550804.html。起初以为this和$(this)就是一模子刻出来。但是我在阅读时,和coding时发现,总不是一回事。What is "this"?In many object-oriented programming languages, this (or self) is a keyword which can be used in in 阅读全文
jquery 中Map、each的应用
2013-02-28 18:28 by youxin, 459 阅读, 收藏, 编辑
摘要:
jQuery.map( array, callback(elementOfArray, indexInArray) )The function can return:the translated value, which will be mapped to the resulting arraynu... 阅读全文
jquery ajax loading效果
2013-02-24 22:26 by youxin, 2179 阅读, 收藏, 编辑
摘要:
<script type="text/javascript" src="jquery-1.3.2.js"></script><script type="text/javascript">$(function() {$("#loading_img").click(function(){$.ajax({type:"GET",url:"demo.php",data:"name=wuxiaoyong",beforeSend:lo 阅读全文