使用复选框启用/禁用多个按钮

问题描述 投票:0回答:1

我是一个新手,实际上对Java语言一无所知,所以我事先表示歉意。

我有两个要禁用的按钮,直到单击复选框。似乎只有一个按钮可以使用我的代码。

function terms_changed(termsCheckBox) {
	//If the checkbox has been checked
	if (termsCheckBox.checked) {
		//Set the disabled property to FALSE and enable the button.
		document.getElementById("submit_button2").disabled = false;
	} else {
		//Otherwise, disable the submit button.
		document.getElementById("submit_button2").disabled = true;
	}
}

function terms_changed(termsCheckBox) {
	//If the checkbox has been checked
	if (termsCheckBox.checked) {
		//Set the disabled property to FALSE and enable the button.
		document.getElementById("test").disabled = false;
	} else {
		//Otherwise, disable the submit button.
		document.getElementById("test").disabled = true;
	}
}
<form method="post">
	<div><label for="terms_and_conditions">I understand</label><input type="checkbox" id="terms_and_conditions" onclick="terms_changed(this)" /></div>
	<div>
		<button id="test" button type="button" disabled onclick="window.location.href = '/innovation/vision-test/amd/';">Start 1st test</button>

		<button id="submit_button2" button type="button" disabled onclick="window.location.href = '/innovation/vision-test/acuity/';">Start the 2nd test</button>
	</div>
</form>
javascript html button
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.