我试图了解是否有机会从HTML标记/节点获取唯一ID而不使用标记上的id属性,我的情况是这样的:
customlocation.gpx
使用myScript.js我想以独特的方式识别两个div,例如:
xcode
编辑:
有关案件的更多信息:
<!-- div #1 -->
<div style="width:200px; height:200px;"><script src="myScript.js"></script></div>
<!-- div #2-->
<div style="width:200px; height:200px;"><script src="myScript.js"></script></div>
提前致谢
答案 0 :(得分:0)
如果您知道它们出现的顺序,那么在"PricedItineraries": {
"AirItinerary": {
"OriginDestinationOptions": {
"OriginDestinationOption": [{
"FlightSegment": [{
"DepartureAirport": {
"LocationCode": "JFK"
},
"ArrivalAirport": {
"LocationCode": "LAX"
},
"MarketingAirline": {
"Code": "AA"
},
"ArrivalTimeZone": {
"GMTOffset": -7
},
"TPA_Extensions": {
"eTicket": {
"Ind": true
}
},
"StopQuantity": 0,
"ElapsedTime": 376,
"ResBookDesigCode": "B",
"MarriageGrp": "O",
"Equipment": {
"AirEquipType": "32B"
},
"DepartureDateTime": "2018-07-07T07:00:00",
"ArrivalDateTime": "2018-07-07T10:16:00",
"FlightNumber": 33,
"OnTimePerformance": {
"Level": 9
},
"OperatingAirline": {
"FlightNumber": 33,
"Code": "AA"
},
"DepartureTimeZone": {
"GMTOffset": -4
}
}],
"ElapsedTime": 376
}, {
"FlightSegment": [{
"DepartureAirport": {
"LocationCode": "LAX"
},
"ArrivalAirport": {
"LocationCode": "JFK"
},
"MarketingAirline": {
"Code": "AA"
},
"ArrivalTimeZone": {
"GMTOffset": -4
},
"TPA_Extensions": {
"eTicket": {
"Ind": true
}
},
"StopQuantity": 0,
"ElapsedTime": 335,
"ResBookDesigCode": "B",
"MarriageGrp": "O",
"Equipment": {
"AirEquipType": "32B"
},
"DepartureDateTime": "2018-07-09T15:30:00",
"ArrivalDateTime": "2018-07-10T00:05:00",
"FlightNumber": 2201,
"OnTimePerformance": {
"Level": 8
},
"OperatingAirline": {
"FlightNumber": 2201,
"Code": "AA"
},
"DepartureTimeZone": {
"GMTOffset": -7
}
}],
"ElapsedTime": 335
}]
},
"DirectionInd": "Return"
},
"TPA_Extensions": {
"ValidatingCarrier": {
"Code": "AA"
}
},
"SequenceNumber": 3,
"AirItineraryPricingInfo": {
"PTC_FareBreakdowns": {
"PTC_FareBreakdown": {
"FareBasisCodes": {
"FareBasisCode": [{
"BookingCode": "B",
"DepartureAirportCode": "JFK",
"AvailabilityBreak": true,
"ArrivalAirportCode": "LAX",
"content": "QUAJZNB3"
}, {
"BookingCode": "B",
"DepartureAirportCode": "LAX",
"AvailabilityBreak": true,
"ArrivalAirportCode": "JFK",
"content": "QUAJZNB3"
}]
},
"PassengerTypeQuantity": {
"Quantity": 1,
"Code": "ADT"
},
"PassengerFare": {
"FareConstruction": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "249.30"
},
"TotalFare": {
"CurrencyCode": "USD",
"Amount": "296.40"
},
"Taxes": {
"TotalTax": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "47.10"
},
"Tax": [{
"CurrencyCode": "USD",
"DecimalPlaces": 1,
"TaxCode": "AY",
"Amount": 11.2
}, {
"CurrencyCode": "USD",
"DecimalPlaces": 1,
"TaxCode": "US1",
"Amount": 18.7
}, {
"CurrencyCode": "USD",
"DecimalPlaces": 0,
"TaxCode": "XF",
"Amount": 9
}, {
"CurrencyCode": "USD",
"DecimalPlaces": 1,
"TaxCode": "ZP",
"Amount": 8.2
}]
},
"BaseFare": {
"CurrencyCode": "USD",
"Amount": "249.30"
},
"EquivFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "249.30"
}
},
"Endorsements": {
"NonRefundableIndicator": true
}
}
},
"FareInfos": {
"FareInfo": [{
"TPA_Extensions": {
"Cabin": {
"Cabin": "Y"
},
"SeatsRemaining": {
"BelowMin": false,
"Number": 7
}
},
"FareReference": "B"
}, {
"TPA_Extensions": {
"Cabin": {
"Cabin": "Y"
},
"SeatsRemaining": {
"BelowMin": false,
"Number": 7
}
},
"FareReference": "B"
}]
},
"TPA_Extensions": {
"DivideInParty": {
"Indicator": false
}
},
"ItinTotalFare": {
"FareConstruction": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "249.30"
},
"TotalFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "296.40"
},
"Taxes": {
"Tax": [{
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"TaxCode": "TOTALTAX",
"Amount": "47.10"
}]
},
"BaseFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "249.30"
},
"EquivFare": {
"CurrencyCode": "USD",
"DecimalPlaces": 2,
"Amount": "249.30"
}
}
},
}
返回的列表中,第一个将在第二个之前。例如:
querySelectorAll
&#13;
var list = document.querySelectorAll("#container div");
var n = 0;
setInterval(function() {
list[n].classList.remove("highlight");
n = n == 0 ? 1 : 0;
list[n].classList.add("highlight");
}, 500);
&#13;
.highlight {
color: blue;
}
&#13;
答案 1 :(得分:0)
您可以使用:
但是如果你不想修改html,你甚至可以选择样式属性,(不是最好的方法......)
var elms = document.querySelectorAll('*[style="width:200px; height:200px;"]');
elms[0].style.background='red';
&#13;
7
&#13;
<!-- div #1 -->
<div style="width:200px; height:200px;">testing 1 2 3</div>
<!-- div #2-->
<div style="width:200px; height:200px;">testing 1 2 3</div>
&#13;