JS当前属性查询实现代码
单页面下载
网站标题
#div1 .bObject
{
cursor:pointer;
color:Blue;
}
#div1 .bError
{
color:Red;
}
#div1 div
{
margin-left:20px;
border:solid 1px gray;
padding:5px;
}
#div1 th
{
text-align:left;
background-color:#fef;
}
#div1 td
{
vertical-align:top;
}
function getObject() {
var chkNull = document.getElementById('chkNull');
eval('var obj=' + document.getElementById('txt').value + ';');
var str = '
类型 | 名称 | 值 | ||
---|---|---|---|---|
' + typeof (obj[i]) + ' | ' + i + ' | ' + i + ' | ' + formatHTML(obj[i]) + ' | ' + obj[i] + ' |
' + i + ' error:' + e + ' |
';
var div1 = document.getElementById('div1');
div1.innerHTML = str;
var bs = div1.getElementsByTagName('b');
for (var i = 0; i 10000) {
return '字符长度:' + strHTML.length + '字节';
}
strHTML = strHTML.replace(/&/g, '&');
strHTML = strHTML.replace(//g, '>');
strHTML = strHTML.replace(/\n/g, '
');
strHTML = strHTML.replace(/\t/g, ' ');
strHTML = strHTML.replace(/ /g, ' ');
return strHTML;
}
function goUp() {
var txt = document.getElementById('txt');
if (txt.value.lastIndexOf(']') == txt.value.length - 1) {
txt.value = txt.value.substr(0, txt.value.lastIndexOf('['));
getObject();
return;
}
if (txt.value.indexOf('.') != -1) {
txt.value = txt.value.substr(0, txt.value.lastIndexOf('.'));
getObject();
return;
}
}
function show() {
var txt = document.getElementById('txt');
var r = /^\+?[0-9][0-9]*$/; //正整数
if (r.test(this.innerHTML)) {
txt.value += '[' + this.innerHTML + ']';
}
else {
txt.value += '.' + this.innerHTML;
}
getObject();
}
屏蔽空值
getObject();
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
打包下载