[英]Javascript radio button into dropdown w/ validation
I'm looking to change this code into a dropdown menu, changing the list is fine but cant figure out the onclick event. 我想将此代码更改为下拉菜单,更改列表很好,但无法确定onclick事件。
for (var z = 0; z < ShipTable.length; z++)
sOutput += "< input type=radio name=\"ZONE\" value=\"" + z
+ "\"" + (z == ZoneChecked ? " checked" : "")
+ " onClick=\"NewZone(this.value)\">" + ShipTable[z].zone + ";
I've changed the above into 我已将以上内容更改为
sOutput += "<select class=\"nopselect\" onClick=\"NewZone()\"><option>Select Delivery< /option>";
for (var z = 0; z < ShipTable.length; z++)
sOutput += "< option name=\"ZONE\" value=\"" + z
+ "\" >" + ShipTable[z].zone + "</option>";
sOutput += " < /select>< /TD > < /TR>";
but this function want this function to work with the drop down 但此功能希望此功能与下拉菜单一起使用
function NewZone(value) {
SetCookie("ZoneSelected", value, null, "/");
var RegionCookie = iGetCookie("RegionSelected");
if (RegionCookie != null && RegionFromZone.length && !Element(RegionCookie, RegionFromZone[ZoneParam])) DeleteCookie("RegionSelected", "/");
location.href = location.href;
}
You may want to use the onChange
event instead of onClick. 您可能要使用
onChange
事件而不是onClick。
sOutput += "<select class=\"nopselect\" onChange=\"NewZone()\"><option>Select Delivery< /option>";
onChange is triggered when you change your selection in the dropdown, instead of when you simply click somewhere on it. 当您在下拉菜单中更改选择时(而不是仅单击它的某个位置)时,就会触发onChange。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.