gpt4 book ai didi

javascript - 显示具有数值的元素

转载 作者:行者123 更新时间:2023-12-03 04:47:46 26 4
gpt4 key购买 nike

如何用数值显示元素,并带有点击功能

html

<p>
<button>Run</button>
</p>

<p>
<span id="demo">1000</span>
</p>

<p id="result">Lorem Ipsum</p>

jquery

$('button').click(function(){
$('#demo').filter(function(index){
var num = parseInt(this.textContent);
return num >= 1000;
}).find('#result').show();
});

CSS

#result{
display:none;
}

<强> Demo Fiddle

最佳答案

您可以使用此代码。基本上,单击按钮时,您将获得数字(innerHTML),如果该数字 >= 1000,则对结果调用 show() 或对结果调用 hide() 。

$('button').click(function(){
var number = $('#demo').html();
if (number >= 1000) {
$("#result").show();
}else{
$("#result").hide();
}
});

Here is the link to updated JSFriddle

关于javascript - 显示具有数值的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42799222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com