你好我的html代码是这样的
<input type="radio" name='answer_value1[<?php echo $survey1->id?>]' value="<?php echo $answer1->id?>" validate="required:true" id="<?php $answer1->valdt == '1' ? print "welcome":""?>" />
这是评论框的代码
<textarea rows="5" cols="55" name="nn[<?php echo $survey1->id?>]" id="comment" ></textarea>
如果单选按钮 ID 是“欢迎”,那么我想让文本区域有效,否则无效。
然后我用jquery写了一些代码
$(function() {
$('input[id="welcome"]')).change(function() {
$('textarea[id="comment"]').each(function(){
$(this).rules("add", {
required: true,
} );
} );
如果我先单击此字段,然后单击另一个单选按钮,它仍会验证此文本区域字段。 请给我一些想法
最佳答案
仅供引用,ajax 不用于验证。它用于从服务器异步获取数据。
if (document.getElementById('welcome').checked) {
var textarea = document.getElementById('comment');
if (textarea.value = '') {
// validation failed
return false;
} else {
return true;
}
}
关于php - 单击特定单选按钮后验证文本区域框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14534801/