【问题标题】:Disable input in html禁用html中的输入
【发布时间】:2013-01-26 17:47:18
【问题描述】:

我正在用 Javascript 和 Jquery 移动版创建 8 拼图游戏。我已经用<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>    

【问题讨论】:

    标签: javascript jquery html input disabled-input


    【解决方案1】:

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

    【讨论】:

    • 不是,我这里是拼写错误,但是我在代码中写了disabled="disabled"!它不起作用,因为 javascript 代码没有执行(onClick 被禁用)并且移动设备仍然显示 kyboard!没有别的办法了吗?
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:
      $("input").attr("disabled","true");  
      

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

      【讨论】:

        猜你喜欢
        • 2010-09-27
        • 2021-02-10
        • 1970-01-01
        • 1970-01-01
        • 2016-11-11
        • 1970-01-01
        • 2012-11-29
        • 2015-09-04
        相关资源
        最近更新 更多