// Register for Activities section of the form.
document.querySelector(".activities").addEventListener("change", function(){
var main = document.querySelector("all").checked;
var framework = document.querySelector("js-frameworks").checked;
var libs = document.querySelector("js-libs").checked;
var express = document.querySelector("express").checked;
var node = document.querySelector("node").checked;
var build = document.querySelector("build-tools").checked;
var npm = document.querySelector("npm").checked;
// If the user selects a workshop, don't allow selection of a workshop at the same date and time -- you should disable the checkbox and visually indicate that the workshop in the competing time slot isn't available.
if(framework == true) {
express.disabled = true;
} else if(express == true) {
framework.disabled = true;
} else if(libs == true) {
node.disabled = true;
} else if(node == true) {
libs.disabled = true;
}
// When a user unchecks an activity, make sure that competing activities (if there are any) are no longer disabled.
if(!framework.checked) {
express.disabled = false;
} else if(!express.checked) {
framework.disabled = false;
} else if(!libs.checked) {
node.disabled = false;
} else if(!node.checked) {
libs.disabled = false;
}
});
<fieldset class="activities">
<legend>Register for Activities</legend>
<label><input type="checkbox" name="all"> Main Conference — $200</label>
<label><input type="checkbox" name="js-frameworks"> JavaScript Frameworks Workshop — Tuesday 9am-12pm, $100</label>
<label><input type="checkbox" name="js-libs"> JavaScript Libraries Workshop — Tuesday 1pm-4pm, $100</label>
<label><input type="checkbox" name="express"> Express Workshop — Tuesday 9am-12pm, $100</label>
<label><input type="checkbox" name="node"> Node.js Workshop — Tuesday 1pm-4pm, $100</label>
<label><input type="checkbox" name="build-tools"> Build tools Workshop — Wednesday 9am-12pm, $100</label>
<label><input type="checkbox" name="npm"> npm Workshop — Wednesday 1pm-4pm, $100</label>
</fieldset>
我加入互動性的形式。
用戶將通過複選框選擇他們想要執行的活動。
如果用戶選擇與另一個時間有衝突的活動。然後,其他複選框將被禁用。
我不想爲此使用jQuery。
我在嘗試執行此操作時遇到問題。該錯誤表示它無法讀取屬性'檢查'null?
我在這裏做錯了什麼?我嘗試過,不管我是否試圖調用價值觀,檢查屬性並嘗試了不少嘗試的解決方案,但無濟於事。相反
document.querySelector("all")
,您可以select elements by name,並採取第一個找到:
你知道'querySelector'的作用嗎? –
我以爲我做到了:返回文檔中與指定的選擇器組相匹配的第一個元素? – gloopit
呃,你沒有。 :)你的複選框的選擇器都是錯誤的。 'document.querySelector(「[name = all]」)'更像它。 –