可以在For循环中添加带有多个ID的getElementById吗? 但首先,您可以使用querySelectorAll列出已出现的ID。
将返回格式化信息的函数:
function show_info(real_info, otp_inf) {
if(real_info.indexOf('already exists') > -1) {
var sinf = real_info.split("File '"+dir_files).pop();
var sinf = sinf.split(' Overwrite').shift();
$('#otp_'+otp_inf).html('<br><i><b class="rev-dev" style="font-size:14px">Not Encoded</b><br /><b>File \''+ sinf +'</b></i>');
}
}
如果我把getElementById放在里面,For循环不起作用的问题是:
var allids = document.querySelectorAll("#all_log div"); // To list all the IDs that have appeared
for (var i = 0; i < allids.length; i++) {
if(allids[i].id.indexOf('bd_') > -1) { // Filter all IDs that start with...
var idinfo = allids[i].id.split('bd_').pop(); // Show only the unknown name of the ID that will show the final text ......
var id_info = document.getElementById(allids[i].id); // this line is not working
show_info(id_info, idinfo);
}
}
这将是ID:
<div id="all_log">
<?php
echo '<div class="hide_log" id="bd_'.md5(current($files)).'">'; //ID with the original text
execOutput($cmd);
echo '</div>';
echo '<div id="otp_'.md5(current($files)).'"></div>'; //ID with part of text
?>
</div>
答案 0 :(得分:0)
在线上,目标是收集ID的html中的文本,所以它出错了:
var id_info = document.getElementById(allids[i].id); // wrong
var id_info = $('#'+allids[i].id).html(); //correct