How can val() return Number?(val() 如何返回数字?)
本文介绍了val() 如何返回数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在val
docs中写了这样的描述:
.val() 返回:字符串、数字、数组
.val() Returns: String, Number, Array
我试图获取一个 Number
,但它似乎只返回 string
,是不是我做错了什么?
I tried to get a Number
, but it seems to return string
only, Is there something that I'm doing wrong?
$('#gdoron').val('1');
alert($('#gdoron').val() === '1'); // true
alert(typeof $('#gdoron').val()); // string.
$('#gdoron').val(1);
alert($('#gdoron').val() === 1); // false
alert(typeof $('#gdoron').val()); // string (not "number"!)
<script src="aHR0cHM6Ly9hamF4Lmdvb2dsZWFwaXMuY29tL2FqYXgvbGlicy9qcXVlcnkvMi4xLjEvanF1ZXJ5Lm1pbi5qcw=="></script>
<input type="text" id="gdoron" />
我的问题是:val()
如何按照文档所述返回数字? 问题不在于如何解析字符串.
My question is: how can val()
return number as the docs says? The question is not about how can I parse the string.
推荐答案
一些 HTML5 元素,例如进展;
Some HTML5 elements e.g. progress;
console.log(typeof $("#prog").val()); // number
<script src="aHR0cHM6Ly9hamF4Lmdvb2dsZWFwaXMuY29tL2FqYXgvbGlicy9qcXVlcnkvMi4xLjEvanF1ZXJ5Lm1pbi5qcw=="></script>
<progress value="50" max="100" id="prog"></progress>
这篇关于val() 如何返回数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:val() 如何返回数字?


猜你喜欢
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06