【发布时间】:2021-09-11 16:14:29
【问题描述】:
我想制作一个脚本来检查 textarea 中是否有超过 10 个字符,以及自定义下拉菜单的 textContent 是否不等于 Choose one。如您所见,它正在工作,但在您从菜单中选择一个选项后,Post 按钮仍处于禁用状态,只有在您在文本区域中写信时才会启用。有什么方法可以在用户选择一个选项后立即启用Post按钮?
代码:
var options = document.getElementById('option-selected-choose-one'); // This is the custom select box
$(document).ready(function(){
$('#cpmsbtndbld').attr('disabled',true); // This is the submit button
$('#post_input_textarea').keyup(function(){
if(options.textContent != 'Choose one' && $(this).val().length > 10) { // If the select tag's value is not `Choose one` and the textarea has more characters than 10
$('#cpmsbtndbld').attr('disabled', false); // Enable the submit button
} else {
$('#cpmsbtndbld').attr('disabled',true); // Stay disabled
}
})
});
【问题讨论】:
-
UM,运行select的onchange逻辑......
-
我已经尝试过了,但没有任何反应。
-
如果你打算重用相同的代码,你不能使用
$(this).val().length。
标签: javascript html jquery drop-down-menu textarea