如何在jquerymobile中获取label的值并将其解析为int

时间:2013-10-02 12:28:48

标签: javascript jquery jquery-mobile cordova parseint

我在jquerymobile工作。我只想从label获取字符串并将其转换为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 --> 

1 个答案:

答案 0 :(得分:0)

string to 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));