admin管理员组文章数量:1405727
I have coded this in Business Catalyst website.
<li class="instock"><span id="stock">Stock</span><span id="stockcount" style="display: none;">{tag_instock}</span> </li>
<script>
var stockcnt = document.getElementById('stockcount').innerHTML;
if (stockcnt==0){
document.getElementById('stock').InnerHTML="Out of Stock";
}else{
document.getElementById('stock').InnerHTML="In Stock";
}
</script>
What i want to do is if stockcount
== 0 change the innerHTML of stock
{tag_instock} will automatically generate number according to the stock count when page loads.
when i tried this code. it didn't work. can anyone show me what I'm doing wrong here.
I have coded this in Business Catalyst website.
<li class="instock"><span id="stock">Stock</span><span id="stockcount" style="display: none;">{tag_instock}</span> </li>
<script>
var stockcnt = document.getElementById('stockcount').innerHTML;
if (stockcnt==0){
document.getElementById('stock').InnerHTML="Out of Stock";
}else{
document.getElementById('stock').InnerHTML="In Stock";
}
</script>
What i want to do is if stockcount
== 0 change the innerHTML of stock
{tag_instock} will automatically generate number according to the stock count when page loads.
when i tried this code. it didn't work. can anyone show me what I'm doing wrong here.
Share asked Sep 30, 2014 at 15:48 CadeLewisCadeLewis 832 gold badges2 silver badges11 bronze badges1 Answer
Reset to default 3JavaScript is case-sensitive, its innerHTML
(lose the capital "I")
document.getElementById('stock').innerHTML="In Stock";
本文标签: javascriptgetElementByIdinnerHTML with if else conditionStack Overflow
版权声明:本文标题:javascript - getElementById.innerHTML with if else condition - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744935271a2633144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论