javascript - querySelectorAll On Multiple Classes Not Working -
i'm trying display multiple clocks on same page. however, queryselectorall doesn't seem doing it. i'm using modern browsers (have tested in chrome , safari). doing wrong?
js code:
/*global document, window */ function checktime(i) { 'use strict'; if (i < 10) { = "0" + i; } return i; } function a() { 'use strict'; var oct = ["0", "1", "2", "3", "4", "5", "6", "7"], octtime, oct1, oct2, oct3, oct4, oct5, oct6, octvalue, point = ".", = new date(), hours = now.gethours(), minutes = now.getminutes(), seconds = now.getseconds(), h = checktime(hours), m = checktime(minutes), s = checktime(seconds), totsecs = [hours * 3600 + minutes * 60 + seconds + (now.gettime() % 1000) / 1000]; octtime = math.floor(totsecs / (86400 / 262144)); oct1 = math.floor(octtime / 32768); octtime -= 32768 * oct1; oct2 = math.floor(octtime / 4096); octtime -= 4096 * oct2; oct3 = math.floor(octtime / 512); octtime -= 512 * oct3; oct4 = math.floor(octtime / 64); octtime -= 64 * oct4; oct5 = math.floor(octtime / 8); octtime -= 8 * oct5; oct6 = octtime; octvalue = point + oct[oct1] + oct[oct2] + oct[oct3] + oct[oct4] + oct[oct5] + oct[oct6]; document.queryselectorall(".c").innerhtml = h + ":" + m + ":" + s; document.queryselectorall(".d").innerhtml = octvalue; window.settimeout(a); } window.onload = a;
html code:
<div class="a"> <table> <tr> <td><b>regular time</b> <td><b>octal time</b> <tr> <td class="c">js problem <td class="d">js problem </table> </div> <br> <div class="a"> <table> <tr> <td><b>regular time</b> <td><b>octal time</b> <tr> <td class="c">js problem <td class="d">js problem </table> </div> <script src="/1.js"></script>
test page: http://www.gloryhood.com/ztest.html
it because queryselectorall returns nodelist not single node element, need iterate , set value
function sethtmlforbyclass(clazz, html) { var nodes = document.queryselectorall('.' + clazz) (var = 0; < nodes.length; i++) { nodes[i].innerhtml = html; } } sethtmlforbyclass('c', h + ":" + m + ":" + s); sethtmlforbyclass('d', octvalue);
Comments
Post a Comment