4

我正在用 Javascript 和 Jquery 移动设备创建 8 个拼图游戏。我已经用 an 完成了这些盒子,<input readonly></input>并将它们全部放在了 9x9 的桌子上。问题是当我点击一个框来移动它时,即使它是只读的,移动设备也会尝试在其中写入并显示键盘。这不是我想要的...我想禁用输入或使用不同于<input>. 我尝试使用 disable="disabled" 但仍然无法正常工作。这是代码:

<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>    
4

3 回答 3

11

你应该使用disabled="disabled"而不是disable="disable"

于 2013-02-11T15:32:11.667 回答
3

如果您使用的是 HTML5,那么包含disabled属性就足够了,因为它是一个布尔属性。

于 2013-02-11T15:35:49.923 回答
3
$("input").attr("disabled","true");  

是 jQuery 解决方案,disabled在标记中设置是 html 解决方案。

于 2013-02-11T15:33:43.773 回答