第一种方法如下
if (typeof beforeReject != 'undefined' && beforeReject instanceof Function) {
beforeReject(nextStep);
}
第二种方法如下
if (对象名.方法名)
{
//方法存在
对象名.方法名();
}
第三种方法:
if(typeof(nl.onBlue)=="function")
{
//存在
}
else
{
//不存在
} ......
以前做项目时候经常用到多行输入框字数的控制以及统计显示的情况,综合了几种情况后现在固定用了这个脚本。
例如 要输入描述textbox
<div>
<h3>
描述:</h3>
<asp:TextBox runat="server" ID="tbdesciption" Height="200px" TextMode="MultiLine" onkeyup="textCounter(this,'shengyu',500)" onkeydown="textCounter(this,'shengyu',500)"
AutoCompleteType="None" Columns="100" MaxLength="1000" Width="500px"></asp:TextBox>
</div>
<div>您还可以输入:<input type="text" readonly="readonly" style=" width:22px; color:Red; border:0px;" mce_style=" width:22px; color:Red; border:0px;" id="shengyu" />个字</div>
javascript代码:
function textCounter(fieldId, countfieId, maxlimit) {
var fieldEle = fieldId;
var countfieldEle = document.getElementById(countfieId);
if (fieldEle == null || countfieldEle == null) {
return false;
}
if (fieldEle.value.gblen() > ......
有时候找到别人写的js代码是压缩过的,通过这个工具可以对代码进行格式化。
<html>
<head>
<title>JS格式化工具 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<mce:style><!--
* { padding:0px; margin:5px; font-size:13px; font-family: arial 宋体; }
body { overflow:auto; border:0px none black; background-color:buttonface; }
li { margin:0px 0px 0px 40px; padding:2px 4px; }
.quote { color:#999; }
.comments { color: #009090; }
.indent { margin-left:25px; }
.regexp { color:#F000F0; }
#divTools { height:20px; border-bottom:1px solid #555; padding-left:15px; }
#divTools a { color:navy; text-decoration:none; height:20px; line-height:20px; padding:0px 25px; }
#divTools a:hover { color:white; background-color:navy; text-decoration:none; height:20px; line-height:20px; }
#divJSInput { display:none; width:600px; height:450px; border:2px outset buttonface; position:absolute; background-color:buttonface; z-Index:2; }
# ......
自定义一个log函数,输出传入函数的对象或者信息.
Log.js
// JScript source code
function
log(category, message, object) {
// If this category is explicitly disabled, do nothing
if
(log.options[category + "Disabled
"]) return
;
// Find the container
var
id = category + "_log
";
var
c = document
.getElementById(id);
// If there is no container, but logging in this category is enabled,
// create the container.
if
(!c && log.options[category + "Enabled
"]) {
c = document
.createElement("div
");
c.id = id;
c.className = "log
";
document
.body.appendChild(c);
}
// If still no container, we ignore the message
if
(!c) return
;
// If timestamping is enabled, add the timestamp
if
(log.options.timestamp)
message = new
Date
() + ":
" + (message ? message : "");
// Create a elemen ......
1. 用类名查找元素
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN
" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
">
<html xmlns="http://www.w3.org/1999/xhtml
" >
<head>
<title>Untitled Page</title>
<script type="text/javascript
">
//本页方法:用类名选择元素
function
getElements(cla) {
var
elements = document
.getElementsByTagName("*
");
var
elems = [];
for
(var
i = 0; i < elements.length
; i++) {
if
(elements[i].className && has(elements[i].className,cla)) {
elems.push(elements[i]);
}
}
return
elems;
}
function
has(ele, name
) {
var
clla = [];
if
(ele) clla = ele.split(' ');
for
(var
i = 0; i < clla.length
; i++)
......
<SCRIPT>
//判断y年的农历中那个月是闰月,不是闰月返回0
function leapMonth(y){
return(lunarInfo[y-1900]&0xf);
}
var lunarInfo=new Array(
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,
0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,
0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,
0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,
0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,
0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,
0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,
0x0c960,0x0d954,0x0d4a0,0x0 ......