2013-02-11 49 views
4

我使用Javascript和jquery mobile創建了8個拼圖盒遊戲。我用<input readonly></input>做了盒子,我把它們都放在9x9的桌子上。問題是,當我點擊一個框來移動它時,即使它是隻讀的,移動設備也會嘗試寫入並顯示鍵盤。這不是我想要的...我想禁用輸入或使用與<input>不同的東西。我嘗試使用禁用=「禁用」,但仍然無法正常工作。 這是代碼:在html中禁用輸入

<form name="box"> 
    </center> 
    <table align="center"> 
     <tr> 
      <td ><input name="casella1" value="8" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
      <td ><input name="casella2" value="5" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
      <td ><input name="casella3" value="2" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
     </tr> 
     <tr> 
      <td ><input name="casella4" value="6" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
      <td ><input name="casella5" value="3" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
      <td ><input name="casella6" value="4" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
     </tr> 
     <tr> 
      <td ><input name="casella7" value="1" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
      <td ><input name="casella8" value="7" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 
      <td ><input name="casella9" value="" onClick="test(this.value)" readonly style="text-align: center; width:50px; height:50px; font-weight:bold; background-color: #C0C0C0; border-style: solid; border-color: black"></td> 

     </tr> 
    </table> 
    </form>  

回答

11

您應該使用disabled="disabled"代替disable="disable"

+0

不,這是我在這裏寫的一個拼寫錯誤,但是我在代碼中寫了disabled =「disabled」!它不工作,因爲JavaScript代碼沒有執行(onClick被禁用),移動設備仍然顯示kyboard!沒有另一種方式? – Malo 2013-02-11 17:20:29

3
$("input").attr("disabled","true"); 

是jQuery解決方案,在標記中設置disabled是html解決方案。

3

如果您使用的是HTML5,那麼包含disabled屬性就足夠了,因爲它是布爾屬性。