gpt4 book ai didi

javascript - 单击禁用按钮时添加 CSS

转载 作者:行者123 更新时间:2023-11-28 08:14:21 26 4
gpt4 key购买 nike

在其他各种帖子之后,我禁用了提交按钮,直到从表单中选择了选项。

我想做的是在单击禁用按钮时突出显示选择框。我认为最简单的方法是将 css border-color 应用于具有点击功能的选择框。但我不确定如何实现这一目标。

到目前为止我的脚本:

$('#submitorder').prop('disabled', true);

function updateFormEnabled() {
if (verifyAdSettings()) {
$('#submitorder').prop('disabled', false);
} else {
$('#submitorder').prop('disabled', true);
}
}

function verifyAdSettings() {
if ($('#course1choice').val() != '' && $('#course2choice').val() != '') {
return true;
} else {
return false
}
}

$('#course1choice').change(updateFormEnabled);

$('#course2choice').change(updateFormEnabled);

我的 html:

<form id="productchoices">
<select name="92" id="course1choice">
<option value="">Select Course 1</option>
<option value="659">Lesson Planning </option>
<option value="660">Teaching One to One </option>
<option value="661">Teaching Teenagers </option>
<option value="662">Teaching Young Learners </option>
</select>

<select name="91" id="course2choice">
<option value="">Select Course 2</option>
<option value="655">Lesson Planning </option>
<option value="656">Teaching One to One </option>
<option value="657">Teaching Teenagers </option>
<option value="658">Teaching Young Learners </option>
</select>

<button type="submit" id="submitorder">Book Now</button>
</form>

最佳答案

请看下面的示例,我修改了一些字段。

<form id="productchoices">
<select name="92" id="course1choice" class="choice">
<option value="">Select Course 1</option>
<option value="659">Lesson Planning </option>
<option value="660">Teaching One to One </option>
<option value="661">Teaching Teenagers </option>
<option value="662">Teaching Young Learners </option>
</select>
<select name="91" id="course2choice" class="choice">
<option value="">Select Course 2</option>
<option value="655">Lesson Planning </option>
<option value="656">Teaching One to One </option>
<option value="657">Teaching Teenagers </option>
<option value="658">Teaching Young Learners </option>
</select>
<button type="submit" id="submitorder">Book Now</button>
</form>
$(document).ready(function () {
$("#submitorder").prop("disabled", true);
$('.choice').on('change', function () {
if ($(this).val() == '') {
$("#submitorder").prop("disabled", true);
} else {
$("#submitorder").prop("disabled", false);
}
});

});

如有任何疑问,请告诉我。 Example code

关于javascript - 单击禁用按钮时添加 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29081951/

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