Javascript 如何显示HTMLpropertiescollection(toString/object属性)
我正在编写一个远程/浏览器内日志记录工具(基本上是一个浏览器内控制台,这样我就可以远程调试移动设备等等),但我在打印/访问一些原始DOM元素和对象(当我将它们记录到控制台时,它们似乎是对象)时遇到了问题。在事件对象上调用Javascript 如何显示HTMLpropertiescollection(toString/object属性),javascript,jquery,dom,Javascript,Jquery,Dom,我正在编写一个远程/浏览器内日志记录工具(基本上是一个浏览器内控制台,这样我就可以远程调试移动设备等等),但我在打印/访问一些原始DOM元素和对象(当我将它们记录到控制台时,它们似乎是对象)时遇到了问题。在事件对象上调用bronsole(不要判断我)时,一些DOM对象没有被循环通过,好像for循环没有将其识别为对象一样。有问题的对象之一是HTMLpropertiescollection。我对这个项目没有特别的需求,但是我正在记录触摸事件,如果能够读取事件对象的所有属性就好了 (function
bronsole
(不要判断我)时,一些DOM对象没有被循环通过,好像for循环没有将其识别为对象一样。有问题的对象之一是HTMLpropertiescollection
。我对这个项目没有特别的需求,但是我正在记录触摸事件,如果能够读取事件对象的所有属性就好了
(function ($) {
$('body').prepend('<div id="eoenuitn345n34ntdhiu45dnth" style="position: fixed; top:0; left: 0; width: 100%; height: 100px; background-color: rgba(0,0,0,0.5); z-index: 1000000; overflow-y: auto; padding-top: 40px;"><div id="seouihtoeuitnei98e797etuiST" style="position:absolute; top: 5px; right: 5px; background-color: #C0504D; height: 20px; width: 20px;"></div></div>');
$('#eoenuitn345n34ntdhiu45dnth').click(function(e){
if($(this).height() <= 150){
$(this).animate({height: '100%'});
}else{
$(this).animate({height: '150px'});
}
});
$('#seouihtoeuitnei98e797etuiST').click(function(e){
e.stopPropagation();
if($(this).parent().height() <= 30){
$(this).parent().animate({height: '100%'});
}else{
$(this).parent().animate({height: '0px'});
}
});
$('#eoenuitn345n34ntdhiu45dnth').on('click','.oseu098oaeuno7e089',function(e){
e.stopPropagation();
if($(this).height() > 15){
$(this).css('height', '15px');
$.each($(this).children('.oseu098oaeuno7e089'), function(){
$(this).css('height', '15px');
});
}else{
$(this).css('height', 'auto');
}
if($('#eoenuitn345n34ntdhiu45dnth').height() <= 100){
$('#eoenuitn345n34ntdhiu45dnth').animate({height: '100%'});
}
});
$('#eoenuitn345n34ntdhiu45dnth').on('click','.oeusn0eui0HTDRh98oeui',function(e){
e.stopPropagation();
});
window.uonteuho8o6e8ued68uou8Color = ['#6BC3FF','#FF494F','#00D3D3','#77FF6B','#DBD300','#D470FF'];
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}
function htmlConsole(param){
var obj = (typeof param.NTDNTH8oe8uidu98NT != 'undefined') ? param.NTDNTH8oe8uidu98NT : param;
var index = (typeof param.sjtnhxsSTHxsnheu9isTH != 'undefined') ? param.sjtnhxsSTHxsnheu9isTH : null;
var preKey = (typeof param.sntuhinegdukx0euetkhe989 != 'undefined') ? '[' + param.sntuhinegdukx0euetkhe989 + ']: ' : '';
var spaceAdd = (typeof param.sNDGHBn788rnFI9 != 'undefined') ? param.sNDGHBn788rnFI9 + '____' : '';
var depth = (typeof param.netnuxie0xbenuihtdNT09 != 'undefined') ? param.netnuxie0xbenuihtdNT09 + 1 : '0';
var element = '';
if(typeof obj != null){
if(typeof obj == 'string' || typeof obj == 'number' || typeof obj == 'boolean'){
element += ('<p class="oeusn0eui0HTDRh98oeui" style="color: white; padding:2px;margin:2px; background-color: orange;"><span style="visibility:hidden">' + spaceAdd + '</span>' + preKey + escapeHtml(String(obj)) + '</p>');
}else{
var end = ('<p style="color: white; padding:2px;margin:2px;"><span style="visibility:hidden">' + spaceAdd + '</span>' + ')</p></div>');
element += ('<div id="oestniSTHSseti897e_' + depth + '" class="oseu098oaeuno7e089" style="color: white; padding:2px;margin:2px; height: 15px; overflow:hidden; cursor: pointer; background-color: ' + window.uonteuho8o6e8ued68uou8Color[depth%6] + '"><span style="visibility:hidden">' + spaceAdd + '</span>' + preKey + Object.prototype.toString.call( obj ) + '(<br>');
if(Object.prototype.toString.call( obj ) == '[object Function]'){
element += ('<p class="oeusn0eui0HTDRh98oeui" style="color: white; padding:2px;margin:2px; background-color: orange;"><span style="visibility:hidden">' + spaceAdd + '___' + '</span>' + escapeHtml(String(obj)) + '</p>');
}
if(depth < 10){ // this is because I fudge up the script with "too much recursion" on big objects. I'm in the middle of solving this, hence the redundant properties
for(var key in obj){
element += htmlConsole({NTDNTH8oe8uidu98NT: obj[key], sNDGHBn788rnFI9: spaceAdd, sntuhinegdukx0euetkhe989: key,netnuxie0xbenuihtdNT09: depth,sjtnhxsSTHxsnheu9isTH: index}).element;
}
}else{
element += end;
return {element: element, obj:obj};
}
element += end;
}
}
return {element: element};
}
$.bronsole = function(obj){
$('#eoenuitn345n34ntdhiu45dnth').prepend(htmlConsole(obj).element);
};
$.fn.bronsole = function(text){
var _this = this;
if(typeof text != 'undefined'){
$('#eoenuitn345n34ntdhiu45dnth').prepend(htmlConsole(text).element);
}
$('#eoenuitn345n34ntdhiu45dnth').prepend(htmlConsole(_this).element);
return this;
};
}( jQuery ));
(函数($){
$('body')。前缀(“”);
$('eoenuitn345n34ntdhiu45dnth')。单击(函数(e){
如果($(this).height()HTMLPropertiesCollection
是父元素的集合,其子元素是特殊的HTML5microdata
元素,这是一个相对较新的东西。因此我认为您正在测试此内容的页面没有microdata
,因此HTMLPropertiesCollection
将为空:我可以console.log(HTMLPropertiesCollection)
我得到了类似于getlength 0 getnames对象{length=0,item=item(),contains=contains()}@iterator@@iterator()item()namedItem()\uu proto\uuu
Werid的东西。我想我需要更多的上下文,我只得到了HTMLPropertiesCollection()
当我记录它时,以及当我为(HTMLPropertiesCollection中的k){console.log(k);}
一件很奇怪的事情。你在使用什么浏览器?我使用的是FF 29。在Chrome 37中甚至都做不到这一点,当我试图用它做任何事情时,只是得到了旧的“ReferenceError:HTMLPropertiesCollection未定义”。