JavaScript利用DOM给页面添加内容
自定义一个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 element to hold the log entry
var
entry = document
.createElement("div
");
entry.className = category + "_message
";
if
(message) {
// Add the message to it
entry.appendChild(document
.createTextNode(message));
}
if
(object && typeof
object == "object
") {
entry.appendChild(log.makeTable(object, 0));
}
// Finally, add the entry to the logging container
c.appendChild(entry);
}
// Create a table to display the properties of the specified object
log.makeTable = function
(object, level) {
// If we've reached maximum recursion, return a Text node instead.
if
(level > log.options.maxRecursion)
return
document
.createTextNode(object.toString
());
// Create the table we'll be returning
var
table = document
.createElement("table
");
table.border = 1;
// Add a Name|Type|Value header to the table
var
header = docum
相关文档:
作用域 Scope
Javascript 中的函数属于词法作用域,也就是说函数在它被定义时的作用域中运行而不是在被执行时的作用域内运行。这是犀牛书上的说法。但“定义时”和“执行(被调用)时”这两个东西有些人搞不清楚。简单来说,一个函数A在“定义时”就是 function A(){} 这个语句执行的时候就 ......
<html>
<mce:script type="text/javascript"><!--
function checkedAll(checked)
{
var ckbArray=document.getElementsByName('ckb');
for(var i=0,len=ckbArray.length;i<len;i++)
{
ckbArray[i].checked=checked;
}
}
function clickbutton()
{
var ckbArra ......
第一种方法如下
if (typeof beforeReject != 'undefined' && beforeReject instanceof Function) {
beforeReject(nextStep);
}
第二种方法如下
if (对象名.方法名)
{
//方法存在
对象名.方法名();
}
第三种方法:
if(typeof(nl.onBlue)=="function")
{
//存在
}
......
以前做项目时候经常用到多行输入框字数的控制以及统计显示的情况,综合了几种情况后现在固定用了这个脚本。
例如 要输入描述textbox
<div>
<h3>
描述:</h3>
<asp:TextBox runat="server" ID="tbdesciption" Height="200px" TextMode="MultiLine" onkey ......
有时候找到别人写的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-fami ......