diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html b/files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html new file mode 100644 index 0000000000..56f1d834be --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/number/parseint/index.html @@ -0,0 +1,82 @@ +--- +title: Number.parseInt() +slug: Web/JavaScript/Reference/Global_Objects/Number/parseInt +tags: + - ECMAScript 2015 + - JavaScript + - Method + - Number +translation_of: Web/JavaScript/Reference/Global_Objects/Number/parseInt +--- +<div>{{JSRef}}</div> + +<h2 id="Summary" name="Summary">概述</h2> + +<p><strong><code>Number.parseInt()</code></strong> 方法依据指定基数 [ 参数 <strong>radix </strong>的值],把字符串 [ 参数 <strong>string</strong> 的值] 解析成整数。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><code>Number.parseInt(<var>string</var>[, <var>radix</var>])</code> +</pre> + +<h3 id="参数">参数</h3> + +<p>{{page("en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt", "Parameters")}} </p> + +<p>参数string:要解析的值。 如果此参数不是字符串,则使用ToString抽象操作将其转换为字符串。忽略此参数中的前导空格。<br> + 参数radix:一个介于2到36之间的整数,代表字符串的基数(数学数字系统中的基)。小心-这并不是默认为10。</p> + +<h3 id="返回值">返回值</h3> + +<p>{{page("en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt", "Return value")}}</p> + +<p>从给定字符串中解析的整数。如果基数小于11,且第一个非空白字符不能转换为数字,则返回NaN。</p> + +<h2 id="描述">描述</h2> + +<p>这个方法和全局的 {{jsxref("parseInt", "parseInt()")}} 函数具有一样的函数功能:</p> + +<pre><code>Number.parseInt === parseInt; // true</code></pre> + +<p>ECMAScript 2015添加了这部分 (其目的是对全局变量进行模块化). 请另见 {{jsxref("parseInt", "parseInt()")}} 获取更多详情和示例.</p> + +<h2 id="Polyfill">Polyfill</h2> + +<pre><code>if (Number.parseInt === undefined) { + Number.parseInt = window.parseInt; +}</code></pre> + +<h2 id="说明">说明</h2> + +<table> + <tbody> + <tr> + <th scope="col">说明</th> + <th scope="col">状态</th> + <th scope="col">评论</th> + </tr> + <tr> + <td>{{SpecName('ES2015', '#sec-number.parseint', 'Number.parseInt')}}</td> + <td>{{Spec2('ES2015')}}</td> + <td>初始定义.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-number.parseint', 'Number.parseInt')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p> + +<p>{{Compat("javascript.builtins.Number.parseInt")}}</p> + +<h2 id="See_also" name="See_also">相关链接</h2> + +<ul> + <li><code>{{jsxref("Global_Objects/Number", "Number()")}}</code></li> + <li>全局的 {{jsxref("Global_Objects/parseInt", "parseInt()")}} 函数</li> +</ul> |