Javascript 禁用html中的输入
我正在用Javascript和Jquery mobile创建8字谜盒游戏。我用Javascript 禁用html中的输入,javascript,jquery,html,input,disabled-input,Javascript,Jquery,Html,Input,Disabled Input,我正在用Javascript和Jquery mobile创建8字谜盒游戏。我用完成了框,并将它们全部放在9x9表中。问题是,当我点击一个框来移动它时,即使它是只读的,移动设备也会尝试在其中写入内容并显示键盘。这不是我想要的…我想要禁用输入或使用与不同的东西。我尝试了disable=“disabled”,但仍然不起作用。 代码如下: <form name="box"> </center> <table align="center">
完成了框,并将它们全部放在9x9表中。问题是,当我点击一个框来移动它时,即使它是只读的,移动设备也会尝试在其中写入内容并显示键盘。这不是我想要的…我想要禁用输入或使用与
不同的东西。我尝试了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=“disabled”
是jQuery解决方案,在标记中设置
disabled
是html解决方案。如果您使用的是HTML5,那么包含disabled
属性就足够了,因为它是一个布尔属性。不,这是我在这里犯的拼写错误,但我在代码中写了disabled=“disabled”!它不工作,因为javascript代码没有执行(onClick被禁用),并且移动设备仍然显示kyboard!没有别的办法吗?
$("input").attr("disabled","true");