javascript - 在html中禁用输入

标签 javascript jquery html input disabled-input

我正在使用 Javascript 和 Jquery 移动版创建 8 盒拼图游戏。我用 <input readonly></input> 做了盒子我把它们都放在一张 9x9 的 table 上。问题是,当我点击一个框来移动它时,即使它是只读的,移动设备也会尝试在其中写入并显示键盘。这不是我想要的...我想禁用输入或使用不同于 <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>    

最佳答案

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

关于javascript - 在html中禁用输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14815300/

相关文章:

使用 ctrl+s 保存链接的 JavaScript

javascript - Verlet 3D 破球

javascript - 重建 Angular JavaScript 数组对象

css - 如何获取图像的高度并将该高度应用于 div?

html - SVG 直线动画 CSS

html - Div 覆盖在其他元素之上,即使 z-index 值较低

javascript - 使用 jQuery 清除输入字段中的值

javascript - Onmouseout 事件不起作用

jQuery 替换文本问题

jquery - 如何将 jQuery Select2 与 AngularJS 结合使用