js对象转换成jquery对象:
jQuery(document).ready(function(){ var links = jQuery("#simple-menu li a"); for(var i=0;i<links.length;i++){ jQuery(links[i]).click(function(){ jQuery(".current").removeClass("current"); jQuery(this).addClass("current");//将js对象包装成jQuery对象 //这里this换成links[i],不会增加current类 }); } });
动态创建form:
<a href="/topics/1" onclick="if (confirm('你确定要删除这篇博客?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', '4k3y+j4gi85qFk7QQugsdEuWiCoOFrLPPLJgye7ERXg='); f.appendChild(s);f.submit(); };return false;">删除</a>
Handling runtime errors in JavaScript using try/catch/finally
alert("I am missing a closing parenthesis //syntax error alert(x) //exception assuming "x" isn't defined yet undefinedfunction() //exception
try{ undefinedfunction() } catch(e){ //catch and just suppress error }
try{ undefinedfunction() alert('I guess you do exist') } catch(e){ alert('An error has occurred: '+e.message) }
try{ undefinedfunction() alert('I guess you do exist') } catch(e){ alert('An error has occurred: '+e.message) } finally{ alert('I am alerted regardless of the outcome above') }
var ajaxrequest=null if (window.ActiveXObject){ //Test for support for different versions of ActiveXObject in IE try { ajaxrequest=new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ ajaxrequest=new ActiveXObject("Microsoft.XMLHTTP") } //end inner try catch (e){ alert("I give up. Your IE doesn't support Ajax!") } //end inner catch } //end outer catch } else if (window.XMLHttpRequest) // if Mozilla, Safari etc ajaxrequest=new XMLHttpRequest() ajaxrequest.open('GET', 'process.php', true) //do something with request
function change_list(){ var q=document.getElementById("search_input"); var str=trim(q.value); if(str!=""){ new Ajax.Request("/friend/find", { method: "post", parameters: "query="+str, evalScripts: true, onComplete: function(request) { element.fire("ajax:complete", request); }, onSuccess: function(request) { element.fire("ajax:success", request); }, onFailure: function(request) { element.fire("ajax:failure", request); } }); } }
function change_group(id,grp){ jQuery.ajax({ type:"post", url:"/friend/change_group", dataType: "json", data:{user_id: id,group: grp}, success:function (result, textStatus) { if(textStatus == "success"){ jQuery("#list"+result.jsonReturn[0]).hide(); jQuery("#group"+result.jsonReturn[0]).html(result.jsonReturn[1]); } } }); }
相关推荐
JS代码收藏大全,常用的脚本收藏(完整版本).
Javascript代码收藏大全1,很不错的代码,值得收藏!!!!!
JS代码收藏大全。。。。。。。。。。。。。。
Javascript代码收藏大全2,很不错的代码,值得珍藏!!!!
非常值得收藏的精品JS代码收藏大全,在这里推荐给各位,以后一定会用到的!
Javascript代码收藏大全 超有用
js代码基础代码收藏合集js代码基础代码收藏合集
我收藏的js图片切换代码 我收藏的js图片切换代码
整理的js的代码,有些是比较常用的,提供大家学习参考
代码很全,用于控制网页,实现网页的种种特效, 酷毙了!
畅无忧代码收藏夹是在天草工作室开发的代码收藏夹基础上进行二次开发而成,添加了代码类别管理功能,修正了一些错误,优化了一些不必要的代码。 畅无忧代码收藏夹功能说明: 收藏您所喜欢的代码片段; JS类代码与CSS...
兼容所有浏览器的设为首页收藏本站js代码
收集的比较全面的脚本语言JavaScript代码大全,值得收藏
当当网上书店案例代码+css+js+images 里面包含了最常用的购物车案例,图片轮播案例,以及上下移动菜单案例,等等,收藏下!
<script type="text/javascript" src="Scripts/BookMark.js"> 3、在使用的地方这样使用(下面说的网址要带上http://): ('你的网址');return false;">设为首页 ('你的网址','你的网站名称');return false;...
javascript 收藏的一些代码很方便很实用,拿来看懂就可以用
收藏您所喜欢的代码片段;...JS类代码 与 CSS类代码 可以演示运行效果; 如果您是成员组身份,您可以与成员分享自己收藏的代码,也可以查看别的成员所收藏的代码; 每个用户只能编辑与删除自己所收藏的代码;
我收藏的js实用代码 我收藏的js实用代码
所有浏览器通用的js添加收藏夹代码支持火狐