我正在寻找一种 Javascript 解决方案,该解决方案将根据在同一表单的其他地方选择的特定下拉值(在标准 HTML 中,由 SQL 生成)启用(在其中放置检查)表单上的复选框。我还没有写任何代码,所以现在没有任何代码可以在这里展示。20 年 4 月 8 日编辑:根据 Giuliano 的出色帮助,我决定添加我放在一起的代码(不起作用),如下所示:<%sSQL = "SELECT OrderTypeID, OrderTypeString FROM LookupOrderTypesII"Set rsOrderTypes = Server.CreateObject("ADODB.RecordSet")rsOrderTypes.Open sSQL, oConnGlobal, adOpenStatic, adLockReadOnly iTotalRecords = rsOrderTypes.RecordcountIf iTotalRecords > 0 Then%><br><b>SERVICE/ORDER TYPE:</b><br><script type="text/javascript"> let select = document.getElementById("cboOrderType"); let checkbox = document.getElementById("chkSkipVenueEventDetails"); select.addEventListener("change", function () { checkbox.checked = select.value == "12|LABOR SALES/PAYMENT"; });</script><select class="rounded" name="cboOrderType" id="cboOrderType"> <option value="Select One" selected>Select One</option> <option value="-9999" <%=IfSelected(iOrderTypeID, "Not Listed-ADD Custom Type")%>>Not Listed-ADD Custom Type</option> <% Do While Not rsOrderTypes.EOF iOrderTypeID = Trim(rsOrderTypes("OrderTypeID")) sOrderTypeString = Trim(rsOrderTypes("OrderTypeString")) %> <option value="<%=iOrderTypeID%>|<%=sOrderTypeString%>"<%=IfSelected(sOrderTypeString, sOrderTypeString_NewRequest)%>><%=sOrderTypeString%></option> <% rsOrderTypes.MoveNext Loop %></select><% rsOrderTypes.Close Set rsOrderTypes = NothingEnd If%>'''The SQL code generates the following code (as viewed in browser source):'''</select>这是复选框 HTML:<input type="checkbox" name="chkSkipVenueEventDetails" id="chkSkipVenueEventDetails"> <strong>Skip Venue & Event Details</strong>
1 回答
牧羊人nacy
TA贡献1862条经验 获得超7个赞
您可以简单地将事件侦听器添加到选择的“更改”事件中,并根据选择的值更改复选框的“已选中”属性
html:
<html>
<head></head>
<body>
<select id="select">
<option value="a" selected>something</option>
<option value="b">check</option>
</select>
<label>
<input id="checkbox" type="checkbox">
Checkbox
</label>
<script>
let select = document.getElementById("select");
let checkbox = document.getElementById("checkbox");
select.addEventListener("change", function () {
checkbox.checked = select.value !== "a";
});
</script>
</body>
</html>
添加回答
举报
0/150
提交
取消