[英]Rewriting a div using javascript
I am trying to rewrite a tag using Javascript. 我正在尝试使用Javascript重写标签。 The code looks like this
代码看起来像这样
<div id="captcha" style="display: none;">
[content]
</div>
So I am trying to rewrite the entite tag so it removes the styling 因此,我试图重写entite标签,以便删除样式
"style="display:none;"
From the tag on pageload. 从页面加载中的标记。 I already have this code, but I cannot seem to get it to work:
我已经有了这段代码,但似乎无法正常工作:
var divv = document.getElementById("captcha");
divv.innerHTML = divv.innerHTML.replace("style="display: none;", "");
You're doing it wrong. 你这样做是错的。
Here is the good way : 这是个好方法:
document.getElementById("captcha").style.display='';
尝试使用:
document.getElementById("captcha").style.display='';
You are trying to change the innerHTML of the div#capthca, not the attribute called style. 您正在尝试更改div#capthca的innerHTML,而不是更改名为style的属性。
var divv = document.getElementById("captcha");
divv.style.display = '';
See the fiddle here: http://jsfiddle.net/Lbx9uuLL/ 在这里查看小提琴: http : //jsfiddle.net/Lbx9uuLL/
你应该用
div.attr("style").replace();
Try this- 尝试这个-
var divv = document.getElementById("captcha");
divv.style.display = 'block';
You've made some common and obvious mistake as well: 您还犯了一些常见的明显错误:
"style="display: none;"
* * *
(please note the 3 quote marks!) (请注意3个引号!)
you have to use different quote marks, like '', not "" if your content also have "" 如果您的内容也带有“”,则必须使用不同的引号,例如“”,而不是“”
For example (theoretically) 'style="display: none;"' 例如(理论上)'style =“ display:none;”'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.