我有一个禁用的下拉列表,我只想在单击它后启用它。我尝试了几种方法,以下是不起作用的最新版本:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function() {
$("input:disabled").closest("div").click(function() {
$(this).find("input:disabled").attr("disabled", false).focus();
});
});
<div>
<select name="test" id='testing' disabled>
<option name="first" value='first'>first</option>
<option name="second" value="second">second</option>
</select>
</div>
最佳答案
$(function() {
$('div > div').on('click', function(event) {
$(this).hide().prev('select:disabled').removeAttr('disabled').focus();
});
});
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<form action="" id="myForm">
<div style="display:inline-block; position:relative;">
<select name="test" id="testing" disabled>
<option name="first" value='first'>first</option>
<option name="second" value="second">second</option>
</select>
<div style="position:absolute; left:0; right:0; top:0; bottom:0;"></div>
</div>
</form>
</body>
</html>
关于javascript - 使用 onclick 启用禁用下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51849438/