==============================
>> 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
}
]
==============================