使用innerHTML修改HTML文本和/或替换 [英] Modifying HTML text using innerHTML and/or replace
问题描述
因此,到目前为止,我已经在这个jQuery问题上停留了好几天. 我正在开发一个从Mobile派生的Web应用程序,我的公司通过了NetBiscuits移动版.
So I have been stuck on this jQuery problem for days at this point. I am working on a Web Application that was derived from Mobile and my company goes through NetBiscuits for mobile.
长话短说,NetBiscuits使用它们自己的标记,因此我无法从错误消息中显示此字符串'[BR] [BR]'. [BR]是换行符的BML,我需要一些jQuery才能从我们的Web应用程序中删除该傻瓜!
Long story short NetBiscuits uses their own markup and I cannot get this string'[BR][BR]'from showing up in an error message. [BR] is the BML of line break and I need some jQuery to take that sucker out of our web app!
[]本质上必须< >或什么都不做(首选)
[ ] essentially needs to be < > or nothing (preferred)
我给出了以下形式:error div id为"erMsg".这是我的JavaScript代码:
I gave the form: errors a div id of "erMsg." Here's my code in javascript:
document.getElementById("erMsg").value = document.getElementById("erMsg").innerHTML(erMsg.replace('[BR][BR]', '<br><br>'));
我已经尝试过使用jQuery和JS,innerHTML和replace()的无数方法和实践. 任何帮助将被最亲切地接受.
I have tried countless methods and practices both using jQuery and JS, innerHTML and replace(). ANY help would be most graciously accepted.
推荐答案
innerHTML
不是函数,而是属性.您分配给它.
innerHTML
is not a function, it's a property. You assign to it.
尝试一下:
var elem = document.getElementById('erMsg');
elem.innerHTML = elem.innerHTML.replace(/\[br\]/ig,'<br />');
这篇关于使用innerHTML修改HTML文本和/或替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!