나는 변경하려는 radioBox
로를 checkBox
복수 선택하십시오.
내 확인란은 다음과 같습니다.
<input id="ser-price" name="price" class="w3-check" value="Serviceable {{ price.getServiceablePrice }}" type="checkbox">
나는 그것을 변경했지만 항상 하나의 값을 취합니다. 이것은 파일에서 수행 Javascript
했기 때문에 내 기능을 따릅니다 .block javascript
HTML.Twig
function closeWindowAndShowAlert(f) {
var radios = document.getElementsByName('price');
var price;
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
price = radios[i].value;
break;
} else {
price = null;
}
}
var priceChosen = document.getElementById("priceChosen").value;
if (!price && !priceChosen) {
alert("Please choose a price");
return false;
}
else {
alert("This article has been successfully added to the cart");
return true;
}
}
다중 선택을 선택하도록 내 기능을 수정하려면 어떻게해야합니까?
가격을 0으로 초기화하고 그 안에 값을 추가해야한다고 생각합니다.
var price = 0;
그리고 루프 +=
에서 마지막으로 추가 된 값에 추가하는 데 사용해야 합니다.
price += +radios[i].value; // + prefix will convert the string to numbers
// break; // <---i guess this isn't required
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다