php - Javascript onclick 与 getElementById 不起作用

标签 php javascript html

用于启用 html 文本框的简单 onclick 函数不起作用...单击文本框时没有任何反应。使用变量作为 id 的一部分。

<script language="JavaScript">

function unlock(id)
{
    document.getElementById('strain'+id).disabled=false;
    return false;
}

    </script>


<input id="strain343" type="text" value="54.24" onclick="return unlock(343);" disabled="true" name="strain"></input>

最佳答案

禁用的输入不会捕获点击事件。

参见a simplified demo .

另请参阅the specification :

A form control that is disabled must prevent any click events that are queued on the user interaction task source from being dispatched on the element.

<小时/>

您需要重新考虑您的 UI,以避免该元素被禁用或避免需要单击它。

关于php - Javascript onclick 与 getElementById 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16424214/

相关文章:

php 使用 exec() 返回 127

php - TCPDF 防止 div 进入新页面

php - 使用 PDO 和 bootstrap 向现有 html 表添加新行

c# - JSON 与 XML - XML 是否需要 'local proxy' ?那是什么?

javascript - 使用 Promise 在循环内调用 ajax

php - 在 html 中回显 html 值

html - slider 中的内容不适合移动设备

jquery - 如何将 img 附加到 div 并淡入

html - 如何使响应式电子邮件表格中的列图像保持相同高度

javascript - 用 jest 测试函数