javascript object array string converter
function object2String(obj)
{
var val, output = "";
if (obj)
{
output += "{";
for (var i in obj)
{
val = obj[i];
switch (typeof val)
{
case ("object"):if (val[0]){output += i + ":" + array2String(val) + ",";}else{output += i + ":" + object2String(val) + ",";}break;
case ("string"):output += i + ":'" + encodeURI(val) + "',";break;
default:output += i + ":" + val + ",";
}
}
output = output.substring(0, output.length-1) + "}";
}
return unescape(output);
}
function array2String(array)
{
var output = "";
if (array)
{
output += "[";
for (var i in array)
{
val = array[i];
switch (typeof val)
{
case ("object"):
if (val[0])
{output += array2String(val) + ",";}
else
{output += object2String(val) + ",";}
break;
case ("string"):
output += "'" + encodeURI(val) + "',";
break;
default:
output += val + ",";
}
}
output = output.substring(0, output.length-1) + "]";
}
return unescape(output);
}
function string2Object(string)
{
eval("var result = " + decodeURI(string));return result;
}
function string2Array(string)
{
eval("var result = " + decodeURI(string));return result;
}
²âÊÔ´úÂ룺
function coworker(name, age, dept) {this.name = name;this.age = age;this.department = dept;}
var obj = {};
obj.name="detp one";
obj.action="sale";
var kevin = new coworker("Kevin", 28, obj);
var objStr = object2String(kevin);
alert(objStr);
Óõ½µÄ×ÊÁÏ£º
var str="http://hi.baidu.com/bbjjss2008l?country=Öйú&name=jz";
var urlStr=escape(str);
doc
Ïà¹ØÎĵµ£º
Code:
<!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>ÎÞ±êÌâÒ³</title>
<mce:script language="javascript" type="te ......
1. oncontextmenu="window.event.returnValue=false" ½«³¹µ×ÆÁ±ÎÊó±êÓÒ¼ü
<table border oncontextmenu=return(false)><td>no</table> ¿ÉÓÃÓÚTable
2. <body onselectstart="return false"> È¡ÏûÑ¡È¡¡¢·ÀÖ¹¸´ÖÆ
3. onpaste="return false" ²»×¼Õ³Ìù
4. oncopy="return false;" oncut="re ......
¸Õ¸Õ°Ý¶ÁÁË JavascriptµÄ±äÁ¿Óëdelete²Ù×÷·û ºÜÊÜÆô·¢¡£ÔÎÄֻ˵Á˽á¹û£¬Ã»¸üÉîÈëÍÆÀí×ܽáÒ»ÏÂΪʲô£¬ÒÔ¼°ÔõôÀí½âºÃÒ»µã£¬ÎÒÕâÀï²¹³ä×ܽáһϡ£
/// <reference path="http://tech.idv2.com/2008/01/09/javascript-variables-and-delete-operator/" />
/*
Óëc++²»Í¬£¬javascriptµÄdelete²»»áɾ³ ......
ͼÏñµØͼָµÄÊÇ´øÓпɵã»÷ÇøÓòµÄͼÏñ¡£
ʵÀý
¼òµ¥µÄ HTML ͼÏñÓ³Éä
±¾ÀýÑÝʾһ·ùûÓÐÌí¼Ó JavaScript µÄͼÏñÓ³Éä¡£
Ìí¼ÓÁË JavaScript µÄͼÏñÓ³Éä
±¾ÀýÑÝʾһ·ùÌí¼ÓÁË JavaScript µÄͼÏñÓ³É䣬µ±Êó±ê¸¡¶¯ÓÚij¸öÈȵãÉÏʱ£¬»áµ÷Óà JavaScript º¯ÊýÀ´ÏÔʾÈȵãËù¶ÔÓ¦µÄÐÇÇòµÄ¼ò½é¡£
JavaScript ͼÏñµØͼ
ÎÒÃÇÒѾ ......
1. oncontextmenu="window.event.returnValue=false" ½«³¹µ×ÆÁ±ÎÊó±êÓÒ¼ü
<table border oncontextmenu=return(false)><td>no</table> ¿ÉÓÃÓÚTable
2. <body onselectstart="return false"> È¡ÏûÑ¡È¡¡¢·ÀÖ¹¸´ÖÆ
3. onpaste="return false" ²»×¼Õ³Ìù
4. oncopy="return false;" oncut="re ......