博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JQuery 学习
阅读量:5202 次
发布时间:2019-06-13

本文共 14531 字,大约阅读时间需要 48 分钟。

==============================>> document.cookie ==============================get ip address:202.175.168.133jQuery(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新浪博客免费显示访客IP地址的代码新浪搜狐网易博客网站免费显示访客IP地址的代码:
==============================escape() escape("Visit W3School!
") "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"==============================
$('#Administrator1').prop("checked",true)wrong$('#Administrator1').prop("checked","false")correct $('#Administrator1').prop("checked",false)
function setCheckBoxValue($obj,selName,nonSelName) { if ($obj.prop("checked")) { $obj.attr("name", selName) } else { $obj.attr("name", nonSelName) }; }==============================XMLhttp://demos.kendoui.com/service/Northwind.svc/ProductsJsonphttp://demos.kendoui.com/service/Customers$.getJSON("http://demos.kendoui.com/service/Customers?callback=?",function(data){ console.log(data[0].CustomerID)}); Random DataD:\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多次
...
Go
$("#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:parent')选取拥有子元素的
元素==============================jQuery对象转换成DOM对象:1.var $cr = $("#cr"); // jQuery对象var cr = $cr[0]; // DOM对象alert(cr.checked) //检测这个checkbox2.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");==============================
//另存为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图标
==============================使鼠标滚轮失效function document.onmousewheel() { return false; }// ==============================让下拉框自动下拉
给下拉框分组
==============================读取xml文件var oxmldoc=new ActiveXObject('MSXML');oxmldoc.url="mymsg.xml";var oroot=oxmldoc.root;oroot.children.lengthoroot.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) ==============================禁止选择页面上的文字来拷贝
屏蔽右键菜单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); ==============================closeself.close();setTimeout("self.close()",1000)==============================refreshthis.location.reload();backwindow.history.back();forwardwindow.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.jsvar last=obj.toJSONString(); //将JSON对象转化为JSON字符==============================
>> $('#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"); wrongif(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
list = new List(); 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
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
langList = GetAllLangs.ToList(); List
list = new List(); 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); } ============================================================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元素之后的兄弟元素==============================$("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; } }); }); ============================== ============================== $("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 } ] ==============================

 

转载于:https://www.cnblogs.com/sui84/p/8204857.html

你可能感兴趣的文章
LeetCode 274. H-Index
查看>>
LeetCode 112. Path Sum
查看>>
Json,Gson,Ajax基础知识
查看>>
c#Task类。实现异步的一种方式
查看>>
【待阅】待整理文章列表
查看>>
使用 after 伪类清除浮动
查看>>
自定义模板语言之simple_tag和自定义过滤器
查看>>
oracle数据库
查看>>
(4)模型和数据
查看>>
javascript
查看>>
Terminate program hitting CTRl+C within GDB
查看>>
大龄码农那些事——关于我
查看>>
v-bind、v-on 的缩写
查看>>
在Web应用中接入微信支付的流程之极简清晰版
查看>>
BZOJ 1801: [Ahoi2009]chess 中国象棋( dp )
查看>>
Greg and Array
查看>>
[ext4] 磁盘布局 - extent tree
查看>>
mysql 自动备份脚本
查看>>
linux 设置时区
查看>>
异步路由、单播泛洪产生的安全侦听风险
查看>>