如何在jQueryMobile中获取标签的值并将其解析为int

how to get value of label in jquerymobile and parse it to int

本文关键字:int jQueryMobile 标签 获取      更新时间:2023-09-26

我在jquerymobile中工作。我只想从标签中获取字符串并将其转换为 int,然后递增一个。这是我在jsfiddle中所做的

我的代码是

<div data-role="footer" data-position="fixed" data-tap-toggle="false"> 
                <div data-role="navbar" data-mini="true" >
                    <a href="#" data-role="button" class="HeaderButton" data-icon="edit">&nbsp;</a>
                    <div data-role="controlgroup" data-type="horizontal" style="float: right;padding-right: 2%;">
                        <a href="#" data-role="button" id="aPreviousPage" onclick="PreviousPage()" data-icon="arrow-l" data-iconpos="left" data-theme="a">&nbsp;</a>
                        <a data-role="label" id="aPager" class="ui-disabled" style="padding:0;">2</a>
**<!--  (2)       i want 2 from id="aPager" but it gives me some string with it i m and jquerymobile is already using this  class '.ui-btn-text' -->**

 <a href="#" data-role="button" id="aNextPage"  onclick="NextPage()"   data-icon="arrow-r"  data-theme="a" data-iconpos="notext" data-inline="true">&nbsp;</a>
                    </div>
                </div><!-- /navbar -->
            </div><!-- /footer --> 

字符串到int:parseint(x)其中x =你的字符串

将 int 递增/递减 1:(x + 1) 或 (x - 1),其中 x = 您的起始 int。

组合: (parseint(x) + 1).

在您的示例中:(parseInt($('.ui-btn-text').text()) + 1)

编辑* 此外,在您的 jsfiddle 中,alert('NextPage function=' + parseInt(pager);行缺少结尾")"应该是alert('NextPage function=' + parseInt(pager));