我有一组具有相同名称的复选框。每个复选框都关联一个文本框。在页面加载时,我禁用了所有文本框。单击每个复选框时,应启用与该复选框相对应的文本框。
问题是,我尝试使用不同的代码来启用复选框单击时的文本框。但是复选框单击功能不起作用。
代码如下(我正在使用MVC框架):
{loopstart:setting:100}
{if($setting%2==0)}
<tr height="30">
{endif}
<td align="left">
<input type="checkbox" name="settingcheck" id="setting{$setting[0]}" value="{$setting[0]}"/>{$setting[1]}
</td> <td>
<input type="text" size="2px" id="text{$setting[0]}">
</td>
{if($setting%2==1)}
<td> </td>
{endif}
{loopend:setting}
jQuery查询
$(document).ready(function(){
$("INPUT[type=text]").prop("disabled",true);
$("INPUT[type=text]").css("background-color", "#ccc");
});
此代码用于在页面加载时禁用所有文本框,并且工作正常。
$('input[name='settingcheck']:checked').click(function() {
}
我编写了上面的功能,以在相应的复选框单击时启用文本框。但是此功能不起作用。我尝试在此功能中提醒一些文本。
代码中是否有任何问题。谁能帮我解决这个问题。提前致谢。
字符串文字的格式不正确:由于您曾经用''
文字将其括起来,因此所有'
在字符串中出现的内容都必须转义('input[name=\'settingcheck\']:checked'
)或使用""
来代替
$(document).on('change', 'input[name="settingcheck"]', function() {
if(this.checked){
//this is checked now
} else {
//this is unchecked now
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句