【发布时间】:2015-02-27 16:57:00
【问题描述】:
我按照类似问题的答案的建议阅读了此article。我做了文章所说的一切,但最终结果不是我想要的。
我希望默认禁用文本框。当复选框被选中时,文本框被启用。
发生的事情是默认情况下启用了文本框,并且在选中复选框时,已禁用文本框。
这是我的代码:
<td class="trow2">
{$prefixselect}<input type="text" class="textbox" name="subject" size="40" maxlength="85" value="{$subject}" tabindex="1" />
<input type="checkbox" class="input_control" value="subject" />
<strong>I believe {$forum['name']} is the best section for this topic.</strong>
</td>
<script type="text/javascript">
$(document).ready(function(){
$('.input_control').attr('checked', true);
$('.input_control').click(function(){
if($('input[name='+ $(this).attr('value')+']').attr('disabled') == false) {
$('input[name='+ $(this).attr('value')+']').attr('disabled', true);
}
else {
$('input[name='+ $(this).attr('value')+']').attr('disabled', false);
}
});
});
</script>
【问题讨论】:
标签: javascript html checkbox textbox