有很多关于如何使用 jquery 基于单选按钮选择启用文本字段的帖子。来源:Disable/enable text field with radio button (jQuery)
我对 javascript 的经验为零,并且我无法让这些示例中的任何一个工作。
我尝试了通过 jfiddle 提供的多个示例,但它们不适用于我的应用程序。
所以,有一个 list : 1)javascript一般都可以工作,因为我已经复制并粘贴了一个日期选择器小部件,它工作得很好。 2)我的标签包含了代码片段 3)无论是在正文还是标题中都没有区别。
这是我正在使用的示例代码 在 View 中(这是 codeigniter)
<script src="//code.jquery.com/jquery-1.9.1.js">
//enable a box if the radio button is selected
$('input[name="radioknof"]').on('click', function() {
$(this).next().prop('disabled',false).siblings('input[type=text]').prop('disabled',true);
});
</script>
<input type="radio" name="radioknof" value="text1"/>
<input type="text" id="id1" disabled="disabled"/><br/><br/>
<input type="radio" name="radioknof" value="text2"/>
<input type="text" id="id2" disabled="disabled"/>
显然我错过了像语法错误这样简单的东西......但我一生都看不到它。我不明白的是为什么 jfiddle 可以 100% 工作,而在我的本地服务器上却不能。
(无论选择什么单选按钮,这些框都会被禁用)
最佳答案
您有<script src="//code.jquery.com/jquery-1.9.1.js">
里面有代码。你应该有更多类似的东西:
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
// put your code in here
</script>
</body>
</html>
要么使用 load
您内的事件<head>
。您无法定义src
并将代码放入 <script>
中标签。我个人会使用另一个外部src
也适用于您的其他标记,因此它会缓存到您客户端的浏览器内存中。
关于javascript - 基于单选按钮的 jquery 启用/禁用文本框故障排除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22394076/