중첩 된 for 루프에 문제가 있습니다. 나는 내 양식에서 체크 된 체크 박스의 가치를 결정하려고 노력하고있다. 나는이 모든 일이 그렇게 같은 형식 것을 들었다 :잡히지 않은 TypeError : 객체에 'setAttribute'메소드가 없습니다.
for(checkboxes loop){
for(item.appointmentType[1] loop){
if(statement conditional){
set checks code
}
}
}
그러나 내가 말하는 오류가 발생했기 때문에 난 그냥 제대로 작성 얻을 수없는 것, catch되지 않은 형식 오류 : 개체가있는 방법 '의 setAttribute'
이 없습니다아래 코드는 내가 작업하고있는 코드입니다. 누군가 내가 그 문제를 바로 잡을 수 있도록 도와 줄 수 있습니까?
var checkboxes = document.forms[0].appointmentType;
for(var i=0; i<checkboxes.length; i++){
for(var j=0; j<item.appointmentType[1].length; j++){
if(checkboxes[i].value === item.appointmentType[1][j]){
item.appointmentType[1][j].setAttribute("checked", "checked");
}
}
}
다음은 자바 스크립트와 함께 사용되는 HTML 코드입니다. 모든 자바 스크립트는 자체 .js 파일에 포함되어 있습니다.
<ul><span class="lab">
<li><input type="checkbox" checked value="Get A Free Estimate" id="Get A Free Estimate"
name="appointmentType" /><label for="getAFreeEstimate"><span class="gfe">Get A FREE
Estimate</span></label></li>
<li><input type="checkbox" value=" Lawn Service" id="lawnService" name="appointmentType"/
<label for="lawnService"><span class="ls">Lawn Service</span></label></li>
<li><input type="checkbox" value=" Sprinkler System Service" id="sprinklerSystemService"
name="appointmentType" /><label for="sprinklerSystemService"><span
class="sss">Sprinkler System Service</span></label></li>
<li><input type="checkbox" value=" Flower Bed Maintenance" id="flowerBedMaintenance"
name="appointmentType" /><label for="flowerBedMaintenance"><span class="fbm">Flower
Bed Maintenance</span></label></li>
<li><input type="checkbox" value=" Hedge/Tree Service" id="hedgeTreeService"
name="appointmentType" /><labe for="hedgeTreeService"><span class="hts">Hedge/Tree
Service</span></label></li>
<li><input type="checkbox" value=" Handyman Services" id="handymanServices"
name="appointmentType" /><label for="handymanServices"><span class="hs">Handyman
Services</span></label></li>
<li><input type="checkbox" value=" Other" id="other" name="appointmentType" /><label
for="other"><span class="otr">Other</span></label></li></span></ul><br/>
"아이템"은 어떻게 값을 얻고 있습니까? – Pointy
이 코드와 함께 제공되는 HTML을 보여줄 수 있습니까? – Barmar