innerhtml

Javascript - Change all numbers in a string to subscripts

心不动则不痛 提交于 2020-11-28 02:02:04
问题 I have an input box in which the user inputs a chemical formula. I am displaying their input back to them in a table, with the following code in my javascript file. document.getElementById("entered").innerHTML = userIn; ...where "userIn" is the "id" of the input box, and "entered" is the id of the data in my table row. Now, here's my question: Is there any way I can change all of the numbers in the formula to subscripts, but leaving the letters unchanged? So if H2O2 is entered, only the 2's

How do I clear inner HTML

无人久伴 提交于 2020-07-04 08:29:48
问题 I've been fiddling with this for a while but it won't work and I can't figure out why. Please help. Here is what I have: <html> <head> <title>lala</title> </head> <body> <h1 onmouseover="go('The dog is in its shed')" onmouseout="clear()">lalala</h1> <div id="goy"></div> <script type="text/javascript"> function go(what) { document.getElementById("goy").innerHTML = what; } function clear() { document.getElementById("goy").innerHTML = ""; } </script> </body> </html> The mouseover works and

Hyperlink href incorrectly quoted in innerHTML?

喜你入骨 提交于 2020-06-29 03:47:35
问题 Take this very simple example HTML: <html> <body>This is okay & fine, but the encoding of <a href="http://example.com?a=1&b=2">this link</a> seems wrong.</body> <html> On examining document.body.innerHTML (e.g. in the browser's JS console, in JS itself, etc.), this is the value I see: This is okay & fine, but the encoding of <a href="http://example.com?a=1&b=2">this link</a> seems wrong. This behaviour is the same across browsers but I can't understand it, it seems wrong. Specifically, the

innerHTML return NaN with text

落花浮王杯 提交于 2020-06-27 21:33:41
问题 I got a problem, I try to return a value with innerHTML but I got a NaN. I know my variable is not a number but why he keep telling me that ? function checkWord(id, nameOutput){ var pattern = new RegExp("\\b(hello|world)\\b", "i"); var fieldValue = document.getElementById(id).value; var result = fieldValue.search(pattern); if (result != -1){ document.getElementById(nameOutput).style.color = "green"; document.getElementById(nameOutput).innerHTML = +fieldValue+ " is correct"; } else{ document

innerHTML return NaN with text

半世苍凉 提交于 2020-06-27 21:33:02
问题 I got a problem, I try to return a value with innerHTML but I got a NaN. I know my variable is not a number but why he keep telling me that ? function checkWord(id, nameOutput){ var pattern = new RegExp("\\b(hello|world)\\b", "i"); var fieldValue = document.getElementById(id).value; var result = fieldValue.search(pattern); if (result != -1){ document.getElementById(nameOutput).style.color = "green"; document.getElementById(nameOutput).innerHTML = +fieldValue+ " is correct"; } else{ document

三种创建元素方式区别

橙三吉。 提交于 2020-03-25 19:46:23
1. document.write( )  如果页面文档流加载完毕,再调用这句话会导致页面重绘(根据 document.write()写入的内容,生成新的页面) 2.element.innerHTML  innerHTML 创建多个元素效率更高( 不要拼接字符串,采取数组形式拼接 ),结构稍微复杂  例:   var array = [ ];   for( var i = 0; i < 1000; i++ ){     array.push(" <div style='width:100x;height:10px; border:1px solid red;' ></div> ");   }   document.body.innerHTML = array.join(''); // 速度在10秒内 3.document.createElement()  创建多个元素效率稍微低一点,但是结构清晰 总结:不同浏览器下 innerHTML 效率比 createElement 高  来源: https://www.cnblogs.com/qtbb/p/11676867.html

javascript中innerHTML 获取或替换html内容

China☆狼群 提交于 2020-03-17 01:22:38
innerHTML 属性用于获取或替换 HTML 元素的内容,语法为Object.innerHTML 其中1.Object是获取的元素对象,如通过document.getElementById("ID")获取的元素;2.注意书写,innerHTML区分大小写。 我们通过id="light"获取<div> 元素,并将元素的内容输出和改变元素内容,代码如下: 1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>innerHTML属性</title> 6 </head> 7 <body> 8 <div id="cshi"> 9 你好,黑夜20200317 10 </div> 11 <!-- <script type="text/javascript"> 12 var mylight=document.getElementById('light'); 13 document.write('原始内容:'+mylight.innerHTML+'<br/>');//输入元素内容 14 mylight.innerHTML='javascript tomorrow';//修改元素内容 15 document.write('替换内容:'+mylight.innerHTML); 16 </script> --> 17

innerHTML对比DOM方法,哪个性能好?有什么区别?

亡梦爱人 提交于 2020-03-02 08:03:21
innerHTML对比DOM方法,哪个性能好?有什么区别?是个老生常谈的问题!跟浏览器版本与发展有关! innerHTML是w3c制定的行业标准,几乎所有浏览器都做了支持; 作为原生支持,innerHTML在各主流浏览器下的执行效率是很高的; 但是他有他的缺陷,特别是在ie低版本浏览器下,不支持html5、还有一些其他的标签属性。 直接测试的话,速度明显innerHTML比DOM方法要快很多(包括撸代码的速度),但是有说在webkit内核的浏览器中DOM方法比innerHTML要快。 平时采用jquery框架,对比了html()和append相应的源码,并做了测试,发现在火狐和ie6下,都是html速度快于append。因此建议使用html,当然,涉及事件绑定的话,就没那么方便了。 来源: oschina 链接: https://my.oschina.net/u/656636/blog/465661

innerHTML在主要浏览器中的差异

天大地大妈咪最大 提交于 2020-02-29 13:18:43
废话不多说,直接上代码: <!DOCTYPE html> <head> <script src="http://www.oschina.net/js/2011/jquery-1.5.1.min.js"></script> </head> <body> <script> $(function(){ var div=document.createElement('div'); //设置innerHTML为两个空格 div.innerHTML=' '; //IE:0(IE 9未测),chrome:2 alert(div.innerHTML.length); }); </script> </body> 结论:IE在设置innerHTML时会忽略掉开始的所有空格文本。 事实上jQuery的$.support检测leadingWhiteSpace属性正是这样实现的,检测第一个子节点的nodeType是否是文本类型(nodeType==3)。请看jQuery的源码: var div = document.createElement("div"); div.style.display = "none"; div.innerHTML = " <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a<