2012-07-14 33 views
0

我想用一個WebView製作一個JQuery-mobil應用程序+ Android。JQueryMobile:在運行時將html-input-type更改爲'number'?

該應用程序有一個html-input默認情況下設置爲type="text" 如果最終用戶按輸入然後是標準的Android密鑰彈出窗口。

像這樣:

http://i49.tinypic.com/2rncthi.jpg

這是確定

我需要一個按鈕有改變typetype="number"等按keybord只顯示號碼。

像這樣:

http://i50.tinypic.com/65rjnc.jpg

這是我使用這個HTML:

/*html-input*/ 
<input type="text" name="regnr" value=""/> 

/*Open keybord as number-keybord: </label> 
<a href="#" data-role="button" data-mini="true" id="keybord-as-numbers">Number</a> 

這個jQuery腳本使用replaceWith用於更換輸入標籤按鈕點擊,所以類型設置爲編號

<script> 
$(function(){ 
    //onClick: keybord-as-numbers 
    $("#keybord-as-numbers").click(function(){ 
     $("#regnr").replaceWith(""); 
     $("#div-searchnumber").html('<input type="number" class="searchnumber" data-icon="search" name="regnr" maxlength="4" id="regnr" value="" data-inline="true" autofocus /\>'); 
    }); 
}); 
</script> 

該pro瑕疵是它刪除了CSS樣式,並且我不能replaceWith函數中的html-input, 函數中的值不爲.get

我已經嘗試用$('#regnr').attr('type', 'number');但這並不像這個作品:(

+0

Android的輸入類型尚未最一致的實施。就你而言,也許你最好有兩個輸入控件,並相應地顯示和隱藏它們。 – 2012-07-14 04:22:03

回答

0

退房http://www.texotela.co.uk/code/jquery/numeric/

而且你可以簡單地改變你的類ID和你的網頁上驗證碼:

$(document).ready(function(){ 
    $(".numeric").numeric(); 
}); 

如果您不想使用jQuery,您可以編寫自己的函數並將其稱爲onkeyup事件

請參見:http://www.htmlcodetutorial.com/forms/index_famsupp_158.html

另一種選擇是使用步驟屬性:

http://www.w3.org/TR/html-markup/input.number.html#input.number.attrs.step.float

<input type="number" step="0.01" min="0" > 
+0

嗯.numeric()不會打開我的HTC願望上的鑰匙圈,我會盡量按照田振霖的說法去做! – Voidcode 2012-07-16 18:21:45