如何检查字符串的值

How To Check Value Of String

<span id='amount'>0.00000000</span>
<a class='button-withdraw' id='tombolco' href='#'>Checkout</a>

<script>
    var amount = document.getElementById("amount").innerHTML;
    if (amount >= 0.001) {
        document.GetElementById("tombolco").style = "display:block";
    } else {
        document.GetElementById("tombolco").style = "display:none";
    }
</script>

为什么我的代码不起作用?它有什么问题,我该如何解决?

document.GetElementById("tombolco").style = "display:block";

这不是正确的方法。这是

document.getElementById("tombolco").style.display = 'block';

另请注意,它是 getElementById,而不是大写 G。与 'none' 相同,您的其余代码没问题。

Fiddle

<script>
var amount = document.getElementById("amount").innerHTML;
if (amount >= 0.001) {
document.getElementById("tombolco").style.display = 'block';
} else {
document.getElementById("tombolco").style.display = 'none;
}
</script>

如果您想为元素分配一个 CSS 字符串,就像您尝试做的那样,请使用 style.cssText:

document.getElementById("tombolco").style.cssText = "display:block";