============================== >> document.cookie ============================== get ip address: 202.175.168.133 jQuery(function($){ var url = 'http://chaxun.1616.net/s.php?type=ip&output=json&callback=?&_='+Math.random(); $.getJSON(url, function(data){ alert(data.Ip); });}); ({"Ip":"202.175.168.133","Isp":"???","Browser":"Internet Explorer 8.0","OS":"Windows 7","QueryResult":1}) http://www.cz88.net/ip/index.aspx?ip=202.175.168.133 <iframe src=http://ip.91.com/ip/showip.asp?text=&bg=&line=2&scro=1&leng=180frameborder="0" scrolling="no" width="180" height="30"marginheight="4"marginwidth="0"></iframe> 新浪博客免費顯示訪客IP地址的代碼 新浪搜狐網易博客網站免費顯示訪客IP地址的代碼: <iframesrc=http://ip.91.com/ip/showip.asp?text=&bg=&line=2&scro=1&leng=180frameborder="0" scrolling="no" width="180" height="30"marginheight="4"marginwidth="0"></iframe> <iframe src=http://ip.91.com/ip/showip.asp?text=&bg=&line=2&scro=1&leng=180frameborder="0" scrolling="no" width="180" height="30"marginheight="4"marginwidth="0"></iframe> <iframe width="1800"height="30" frameborder="0" scrolling="no" src="http://chaxun.1616.net/s.php?type=ip&output=json"></iframe> ============================== escape() escape("Visit W3School!<br />") "Visit%20W3School%21%3Cbr%20/%3E" function escapeHTML (str) { var div = document.createElement('div'); var text = document.createTextNode(str); div.appendChild(text); return div.innerHTML; } ============================== encodeURIComponent("http://www.w3school.com.cn") "http%3A%2F%2Fwww.w3school.com.cn" ============================== <input name="SelectedRoles" id="Administrator1" type="checkbox" CHECKED="checked" values="1"/> $('#Administrator1').prop("checked",true) wrong $('#Administrator1').prop("checked","false") correct $('#Administrator1').prop("checked",false) <input type="checkbox" name="SelectedRoles" value="@role.Value" onclick="setCheckBoxValue($(this),'SelectedRoles','NonSelectedRoles')"/> function setCheckBoxValue($obj,selName,nonSelName) { if ($obj.prop("checked")) { $obj.attr("name", selName) } else { $obj.attr("name", nonSelName) }; } ============================== XML http://demos.kendoui.com/service/Northwind.svc/Products Jsonp http://demos.kendoui.com/service/Customers $.getJSON("http://demos.kendoui.com/service/Customers?callback=?",function(data){ console.log(data[0].CustomerID)}); Random Data D:\software\Jquery Plugins\kendoui.web.2013.2.716.open-source\examples\content\shared\js ============================== // $('form input,.form_grp input').blur(function () { // $('.input-validation-error:first').focus(); // return true; // }); 按tab或enter自動跳到下一個input $('form input,.form_grp input').keydown(function () { if (event.keyCode == 9 || event.keyCode == 13) { $(this).parent().next('div').find('input').focus(); return false; } return true; }); ============================== 一直按回車會submit form屢次 <div>... <div class="btn"><a href="javascript:void(0)" >Go</a></div> $("#dialog_go a").click(function (event) { submitRequest(); }); function submitRequest() { if ($("#dialog_go a").prop("disabled")) return false; $("#dialog_go a").prop("disabled", true); $('#dialog_go').attr("style", "display: block; z-index: 90;"); $('#submitForm').submit(); } ============================== 判斷不含某class $(".month_wrapper ul li[class!='bonus']") wrong $(".month_wrapper ul li:not(.bonus)") correct ============================== 回車 $('#ad').keydown(function () { if (event.keyCode == 13) { go(); return false; } return true; }); ============================== 判斷是否隱藏 $('#ad').is(":hidden") ============================== String.substring(start, end) string.substr(start [, length ]) ============================== 交替一組動做 .toggle(function(){},function(){}); 重複切換類名another .toggleClass("another"); ============================== $('div:contains(id)')含有文本di的<div>元素 $('div:parent')選取擁有子元素的<div>元素 ============================== jQuery對象轉換成DOM對象: 1.var $cr = $("#cr"); // jQuery對象 var cr = $cr[0]; // DOM對象 alert(cr.checked) //檢測這個checkbox 2.var $cr = $("#cr"); // jQuery對象 var cr = $cr.get(0); // DOM對象 alert(cr.checked) //檢測這個checkbox是否被選中了 DOM對象轉成jQuery對象 var cr = document.getElementById("cr"); //DOM對象 var $cr = $(cr); // jQuery 對象 alert($cr.is(":checked")) ============================== 給其添加一個名爲highlight的class,而後將其內部li子元素都顯示出來,而且被點擊的.has_children元素的同輩元素都去掉一個名爲highlight的class,以及內部的li子元素通通隱藏。 $(this).addClass("highlight").children("li").show().end().siblings().removeClass("highlight").children("li").hide(); $('pre~siblings') prev元素以後的全部siblings元素,等同於$('prev').nextAll('div') ============================== //在一個id爲table的表格的tbody中,每行最後一列中的checkbox若是沒有被禁用,則把這行的背景設爲紅色 $("#table>tbody>tr:has(td:last:has(:checkbox:enabled))").css("background","red"); ============================== <script language="JavaScript"> //取得機器名,登陸域及登陸用戶名 function getusername() { var WshNetwork = new ActiveXObject("WScript.Network"); alert("Domain = " + WshNetwork.UserDomain); alert("Computer Name = " + WshNetwork.ComputerName); alert("User Name = " + WshNetwork.UserName); } //取得系統目錄 function getprocessnum() { var pnsys=new ActiveXObject("WScript.shell"); pn=pnsys.Environment("PROCESS"); alert(pn("WINDIR")); } //返回系統中特殊目錄的路徑 function getspecialfolder() { var mygetfolder=new ActiveXObject("WScript.shell"); if(mygetfolder.SpecialFolders("Fonts")!=null) { alert(mygetfolder.SpecialFolders("Fonts")); } } //取得磁盤信息 傳入參數如:getdiskinfo('c') function getdiskinfo(para) { var fs=new ActiveXObject("scripting.filesystemobject"); d=fs.GetDrive(para); s="卷標:" + d.VolumnName; s+="------" + "剩餘空間:" + d.FreeSpace/1024/1024 + "M"; s+="------" + "磁盤序列號:" + d.serialnumber; alert(s) } //取得系統目錄 function getprocessnum() { var pnsys=new ActiveXObject("WScript.shell"); pn=pnsys.Environment("PROCESS"); alert(pn("WINDIR")); } //啓動計算器 function runcalc() { var calc=new ActiveXObject("WScript.shell"); calc.Run("calc"); } //讀取註冊表中的值 function readreg() { var myreadreg=new ActiveXObject("WScript.shell"); try{ alert(myreadreg.RegRead ("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\NeroCheck")); } catch(e) { alert("讀取的值不存在!"); } } //寫註冊表 function writereg() { var mywritereg=new ActiveXObject("WScript.shell"); try{ mywritereg.RegWrite("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest","c:\\mytest.exe"); alert("寫入成功!"); } catch(e) { alert("寫入路徑不正確!"); } } //刪除註冊表 function delreg() { var mydelreg=new ActiveXObject("WScript.shell"); if(confirm("是否真的刪除?")) { try{ mydelreg.RegDelete("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\MyTest"); alert("刪除成功!"); } catch(e) { alert("刪除路徑不正確"); } } } //取得文件信息 調用方式如:getfileinfo('c:\\test.pdf') function getfileinfo(para) { var myfile=new ActiveXObject("scripting.filesystemobject"); var fi=myfile.GetFile(para); alert("文件類型:"+fi.type+"文件大小:"+fi.size/1024/1024+"M"+"最後一次訪問時間:"+fi.DateLastAccessed); } //取得客戶端的信息 function clientInfo() { strClientInfo="availHeight= "+window.screen.availHeight+"\n"+ "availWidth= "+window.screen.availWidth+"\n"+ "bufferDepth= "+window.screen.bufferDepth+"\n"+ "colorDepth= "+window.screen.colorDepth+"\n"+ "colorEnable= "+window.navigator.cookieEnabled+"\n"+ "cpuClass= "+window.navigator.cpuClass+"\n"+ "height= "+window.screen.height+"\n"+ "javaEnable= "+window.navigator.javaEnabled()+"\n"+ "platform= "+window.navigator.platform+"\n"+ "systemLanguage= "+window.navigator.systemLanguage+"\n"+ "userLanguage= "+window.navigator.userLanguage+"\n"+ "width= "+window.screen.width; alert(strClientInfo); } </script> //另存爲excel文件並寫入值 function saveas(){ var ExcelApp = new ActiveXObject("Excel.Application"); var ExcelSheet = new ActiveXObject("Excel.Sheet") ExcelSheet.Application.Visible = true; ExcelSheet.ActiveSheet.Cells(1,1).Value = "This is column A, row 1"; ExcelSheet.SaveAs("C:\\TEST.XLS"); ExcelSheet.Application.Quit(); alert('ok'); } ============================== 改變IE地址欄的IE圖標 <link rel="Shortcut Icon" href="index.ico"> ============================== 使鼠標滾輪失效 function document.onmousewheel() { return false; }// ============================== 讓下拉框自動下拉 <select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1"> <option value="">1</option> <option value="">2</option> <option value="">3</option> </select> 給下拉框分組 <select onmouseover="javascript:this.size=this.length" onmouseout="javascript:this.size=1"> <optgroup label="aaa"> <option value="">1</option> </optgroup> <optgroup label="bbb"> <option value="">2</option> <option value="">3</option> </optgroup> </select> ============================== 讀取xml文件 var oxmldoc=new ActiveXObject('MSXML'); oxmldoc.url="mymsg.xml"; var oroot=oxmldoc.root; oroot.children.length oroot.children.item(0).children.item(0).text ============================== 用javascript 判斷文件是否存在 var fso=new ActiveXObject("Scripting.FileSystemObject"); alert(fso.FileExists(filepath)); ============================== 另存爲 document.execCommand('SaveAs','true','aaa.txt') 撤銷上次操做 document.execCommand('undo') 打印 document.execCommand("print") 刷新 location.reload() 或 history.go(0) ============================== 禁止選擇頁面上的文字來拷貝 <script> function noEffect() { with (event) { returnValue = false; cancelBubble = true; } return; } </script> <body onselectstart="noEffect()" oncontextmenu="noEffect()"> 屏蔽右鍵菜單 oncontextmenu="event.returnValue = false" ============================== 最小化窗口(僅對IE單選項窗口有效) window.blur() ============================== 同時按下CTRL和Q鍵 document.onkeydown=function() { if(event.ctrlKey&&event.keyCode==81) {alert(1)} }// ============================== window.external.AddFavorite(url,title); ============================== close self.close(); setTimeout("self.close()",1000) ============================== refresh this.location.reload(); back window.history.back(); forward window.history.forward(); ============================== $.getJSON("http://localhost:16785/StockIn/GetVendorSource?term=l",function(data){ alert(data[0].label);}) var jsonstr=JSON.stringify(json); http://demos.kendoui.com/service/Customers $.getJSON("http://demos.kendoui.com/service/Customers?callback=?",function(data){ console.log(data[0].CustomerID)}); 在json.js var last=obj.toJSONString(); //將JSON對象轉化爲JSON字符 ============================== <input id="data" data-id="45" data-name="inputName"/> >> $('#data').data('name') "inputName" >> $('#data').data('id') 45 ============================== alert (["aaa","bbb"].join(",")) ============================== event.stopPropagation(); event.preventDefault(); ============================== document.selection.empty(); 取消選中 document.selection.createRange().parentElement() window.getSelection().focusNode.parentNode.tagName 選中文本所在的父元素 document.selection.createRange().text; IE使用 window.getSelection().toString(); 標準瀏覽器使用 複製到剪切板 document.selection.createRange().execCommand("Copy") 將gggg複製到剪切板 window.clipboardData.setData('text',"gggg"); wrong if(document.selection) alert("select"); else alert("unselect"); ============================== var amount=Math.floor(Math.random()*1000) ============================== autocomplete // eval($('#VendorSource').val()), $("#SelectLang").autocomplete({ source: '@Url.Action("GetLangSource")', mustMatch: true, change: function (event, ui) { if ($.trim($(event.target).val()) == "") { $("#SelectLangId").val(0); return; } }, select: function (event, ui) { $("#SelectLangId").val(ui.item.id); }, response: function (event, ui) { if (ui.content.length == 0) { $("#SelectLangId").val(0); $(event.target).val(""); return; } } }); public JsonResult GetVendorSource() { List<object> list = new List<object>(); foreach (Vendor vendor in vendorList) { var obj = new { label = vendor.Name, value = vendor.Name, id = vendor.VendorId.ToString() }; list.Add(obj); } return Json(list, JsonRequestBehavior.AllowGet); } public String GetLangSource() { IEnumerable<Langeuage> langList = GetAllLangs.ToList(); // [ { label: "Choice1", value: "value1" }, ... ] string list = "["; foreach (Language lang in langList) { list += "{\"label\":\"" + lang.Name + "\",\"value\":\"" + lang.Name + "\",\"id\":\"" + lang.Id.ToString() + "\"},"; } list += "]"; return list; } $("#SelectLang").autocomplete({ source: eval($('#LangSource').val()), mustMatch: true }); $("#SelectLang").autocomplete({ source: '@Url.Action("GetLangSource")', mustMatch: true }); public JsonResult GetVendorSource() { IEnumerable<Langeuage> langList = GetAllLangs.ToList(); List<object> list = new List<object>(); foreach (Language lang in langList) { var obj = new { label = lang.Name, value = lang.Name, id = lang.Id.ToString() }; list.Add(obj); } return Json(list, JsonRequestBehavior.AllowGet); } ============================== <tr valign="top"><td valign="center" align="center"></td></tr> ============================== jquery-ui-timepicker-addon.js //$('.ui-datepicker-calendar tr td:not(.ui-state-disabled)').click(function () { // $('.ui-datepicker-close').click(); //}); ============================== var passed = false; $("#tabs").tabs({ event: "click", active: "@Model.InitTab", beforeActivate: function (event, ui) { if (ui.newTab.text() == "Items" && $('#StatusId').val() == "@VML.AMMS.Data.Constants.CommonConstants.SaveStatus") { StockIn("@VML.AMMS.Data.Constants.CommonConstants.SaveStatus"); $('#tabs-1 .validationMsg').hide(); var ok = true; if (!passed ) { ok = validate(); } var toDo = function () { passed = true; $('#tabs').tabs("option", "active", 1); //$('#tabs ul li:eq(1) a').focus(); } var notToDo = function () { // (event, ui) { passed = false; var errorMsg = $('#tabs-1 .validationMsg').html(); // event.preventDefault(); //ui.oldTab.focus(); $('#tabs').tabs("option", "active", 0); $('#tabs ul li:eq(0) a').focus(); $('#tabs-1 .validationMsg').html(errorMsg); setTimeout("$('#tabs-1 .validationMsg').html('" + errorMsg + "');$('#tabs-1 .validationMsg').show();", 0); return; } if (!ok) { event.preventDefault(); notToDo(); } else { // event.preventDefault(); if (!passed) { checkUnique($('#tabs-1'), '@Url.Action("CheckUnique", "StockIn")', $('#TransId').val(), $('#SelectVendorId').val(), toDo, notToDo); event.preventDefault(); } else { //Continue event; } } } } }); var passed=false; $("#tabs").tabs({ event: "click", active: 0, beforeActivate: function (event, ui) { if (ui.newTab.text() == "Tab2") { $('#tabs-1 .validationMsg').hide(); var ok = true; if (!passed ) { ok = validate(); //前臺validation } var toDo = function () { passed = true; $('#tabs').tabs("option", "active", 1); //$('#tabs ul li:eq(1) a').focus(); } var notToDo = function () { passed = false; var errorMsg = $('#tabs-1 .validationMsg').html(); // event.preventDefault(); // ui.oldTab.focus(); $('#tabs').tabs("option", "active", 0); $('#tabs ul li:eq(0) a').focus(); setTimeout("$('#tabs-1 .validationMsg').html('" + errorMsg + "');$('#tabs-1 .validationMsg').show();", 0); return; } if (!ok) { event.preventDefault(); notToDo(); } else { if (!passed) { validate2($('#tabs-1'), '/controller/action', toDo, notToDo); //後臺ajax驗證 event.preventDefault(); } } } } }); ============================== var d=new date() d.getFullYear() d.getYear(); d.getMonth(); d.getDay(); d.getHours(); d.getMinutes(); d.getSeconds(); tDate.toDateString() ; ============================== var jsonStr='[{"id":"id","name":"xiaohong"},{"id":"2","name":"xiaoming"}]'; var json=eval(jsonStr); ============================== $('input#item_UnitPrice').keypress(function(event) { var value=$(this).val(); $(this).val(value.replace(/(\.\d)\d+/ig, "$1") ); var keyCode = event.which; if (keyCode == 46 || (keyCode >= 48 && keyCode <=57)) return true; else return false; }); ============================== //$('#assetList tr:first').prepend(html); $(html).insertAfter($('#assetList tr:first')); ============================== $("#content").height(); $("#content").innerHeight();//元素內部區域高度,忽略padding、border $("#content").outerHeight();//忽略邊框 $("#content").outerHeight(true);//包含邊框高度 ============================== var assetDetails = []; assetDetails.push(assetDetail); for (var i = 0; i < tepIds.length ; i++) { var index = jQuery.inArray(tepIds[i], AssetIds) AssetIds.splice(index, 1); AssetDetails.splice(index, 1); } var dataArray = []; var data1="test1"; var data2="test2"; dataArray.push(data1);dataArray.push(data2); dataArray.toString(); // "test1,test2" var index = jQuery.inArray(data2, dataArray) dataArray.splice(index, 1); var ab=[{"name":"aaa","id":1},{"name":"bbb","id":2}] var a={"name":"aaa","id":1} var jsonab=eval(ab); var jsona=eval({"name":"aaa","id":1} ) var filterarray = $.grep(jsonab,function(value){ return value.name =="bbb"; }); ============================== 匹配E元素以後的兄弟元素 <style type="text/css"> div ~ p {background-color:#00FF00;} </style> ============================== $("p").css({ color: "#ff0011", background: "blue" }); ============================== $('#AddInfoLabelDept,#AddInfoLabelPosition').unbind(focus); ============================== $(document).ready(function(){ isEn ?$('#IEVersion').text("Your browser is not supported. Please upgrade to IE8 or higher."):$('#IEVersion').text("????????. ????IE8?????."); ($.browser.msie && navigator.userAgent.indexOf('Trident') <0)?$('#IEVersion').show():$('#IEVersion').hide(); }); ============================== console.log("hello"); var a="hhh"; console.log("hello,%s",a) ============================== >> new Date() console.log("version1 start"+(new Date()).valueOf()); Thu Jun 6 10:19:13 UTC+0800 2013 new Date().getMilliseconds() ============================== 使用$.trim(...),不要用.trim() ============================== $("button").click(function () { $("div").each(function (index, domEle) { // domEle == this $(domEle).css("backgroundColor", "yellow"); if ($(this).is("#stop")) { $("span").text("Stopped at div index #" + index); return false; } }); }); ============================== <select name="multiple" multiple="multiple"> <option selected="selected">Multiple</option> <option>Multiple2</option> <option selected="selected">Multiple3</option> </select> ============================== $("form").serialize(); single=Single&multiple=Multiple&multiple=Multiple3&check=check1&radio=radio1 ============================== $('form').submit(function() { console.log($(this).serializeArray()); return false; }); This produces the following data structure (provided that the browser supports console.log): [ { name: a value: 1 }, { name: b value: 2 }, { name: c value: 3 }, { name: d value: 4 }, { name: e value: 5 } ] ==============================