gpt4 book ai didi

javascript - 如何在选择其他下拉菜单时启用或禁用下拉菜单或文本框?

转载 作者:行者123 更新时间:2023-12-02 18:56:17 24 4
gpt4 key购买 nike

<script>
$('#Select_Font').attr('disabled', 'true');
$('#Enter_Text').attr('disabled', 'true');
$('.dropdownstyle').change(function(){
$(".dropdownstyle option:selected").text();
if($(this).attr('value').match(/Custom$/))
{
$('#Select_Font').attr('disabled', 'false');
$('#Enter_Text').attr('disabled', 'false');
} else if($(this).attr('value').match(/no Thanks$/))
{
$('#Select_Font').attr('disabled', 'true');
$('#Enter_Text').attr('disabled', 'true');
}
});
</script>


<table>
<tbody>
<tr>
<td>
<span>Select type</span>
</td>
<td>
<select class="dropdownstyle">
<option value="No Thanks">No Thanks</option>
<option value="Custom lid (200)">Custom lid (200)</option>
</select>
</td>
</tr>
<tr>
<td>
<span>Select font</span>
</td>
<td>
<select id="Select_Font">
<option value="Arial">Arial</option>
<option value="georgia">georgia</option>
</select>
</td>
</tr>
<tr>
<td>
<span>enter text</span>
</td>
<td>
<input type="text" id="Enter_Text">
</td>
</tr>
</tbody>
</table>

在上面的代码中,最初我希望禁用字体下拉列表和文本框,但在选择自定义表单第一个下拉列表时,我希望启用字体下拉列表和文本框。我不确定我哪里出了问题,所以应该采取什么措施才能使其正常工作。

最佳答案

尝试: SAMPLE

$('#Select_Font, #Enter_Text').attr('disabled', 'disabled');
$('.dropdownstyle').change(function () {
var present = $(this).val().match(/\Custom\b/gi) == null ? true : false;
if(present){
$('#Select_Font, #Enter_Text').prop('disabled', 'disabled');
}
else{
$('#Select_Font, #Enter_Text').removeAttr('disabled');
}
});

$(this).attr('value') 将返回 undefined。您应该使用 $(this).val()

关于javascript - 如何在选择其他下拉菜单时启用或禁用下拉菜单或文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15301119/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com