通过单选按钮的值控制文本区域的元素属性



我只是想知道我是否可以在javascript中获得一些建议或帮助。我是html,jquery和javascript的初学者。我正在尝试根据所选单选按钮值使用 java 脚本控制 jquery 文本区域的元素属性,我通过查看页面的页面源代码来获取文本区域的代码。默认情况下,我的文本区域在元素属性中设置为强制=真,我只是想知道我是否可以使强制性 false 取决于单选按钮的值。我可以成功获取单选按钮的值,但仍然无法控制文本区域的元素属性

用于获取值但不适用于元素属性的单选按钮的代码

$(document).ready(function(){ 
$('input[type=radio][name=Rank]').change(function() {
if (this.value == 'Vip') {
alert("Vip");
$('#Comment').prop('required',false);//I want to set mandatory false
}
else if (this.value == 'not') {
$('#Comment').prop('required',true);//I want to set mandatory true
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-cell"  element-class="org.joget.apps.form.lib.TextArea" element-property="{&quot;id&quot;:&quot;Comment&quot;,&quot;workflowVariable&quot;:&quot;&quot;,&quot;readonlyLabel&quot;:&quot;&quot;,&quot;cols&quot;:&quot;60&quot;,&quot;validator&quot;:{&quot;className&quot;:&quot;org.joget.apps.form.lib.DefaultValidator&quot;,&quot;properties&quot;:{&quot;message&quot;:&quot;&quot;,&quot;custom-regex&quot;:&quot;&quot;,&quot;mandatory&quot;:&quot;true&quot;,&quot;type&quot;:&quot;&quot;}},&quot;value&quot;:&quot;&quot;,&quot;label&quot;:&quot;Comment&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;rows&quot;:&quot;3&quot;}" >
<label class="label">Comment <span class="form-cell-validator">*</span></label>
<textarea id="Comment" name="Comment" cols="60"  rows="3"  ></textarea>
</div>

理想情况下,需要设置为 false 应该可以工作,但您可以在下面尝试

$(document).ready(function(){ 
$('input[type=radio][name=Rank]').change(function() {
if (this.value == 'Vip') {
alert("Vip");
$('#Comment').removeAttr('required');
} else if (this.value == 'not') {
$('#Comment').prop('required',true);//I want to set mandatory true
}
});
});

最新更新