我有一個相當複雜的dom樹,有各種例外等。所以我不想使用將一個jquery函數應用於多個選擇器?
我想做的功能,如「爲每個錯誤消息,我想添加一個類到以前的輸入」。
現在我正在做樹遍歷,但由於各種原因,這不是一個好的解決方案。有沒有一種直接針對正確輸入值的好方法?我完全控制了html,所以如果需要的話,我可以添加類和類似的東西!
實際HTML:
<label for="from">Från</label>
<input value="as" title="Ort, gata eller kommun" name="from" id="from" class="field from input_error" type="text">
<div class="spacer">
<div class="error visible">
<p>Vilken adress menar du? Välj i listan!</p>
<ul>
<li>
<a href="addtrip?from=American%20Samoa&to=&when=&got_car=1&name=&email=&phone=&details=&posted" class="adress">American Samoa</a>
</li>
<li>
<a href="addtrip?from=Assam,%20India&to=&when=&got_car=1&name=&email=&phone=&details=&posted" class="adress">Assam, India</a>
</li>
<li>
<a href="addtrip?from=Elias,%20El%20Gaiara,%20Azbakia,%20Cairo,%20Egypt&to=&when=&got_car=1&name=&email=&phone=&details=&posted" class="adress">Elias, El Gaiara, Azbakia, Cairo, Egypt</a>
</li>
<li>
<a href="addtrip?from=Amberg,%2092224,%20Germany&to=&when=&got_car=1&name=&email=&phone=&details=&posted" class="adress">Amberg, 92224, Germany</a>
</li>
<li>
<a href="addtrip?from=As%20-%20Bras%C3%ADlia,%20Brasilia%20-%20Distrito%20Federal,%20Brazil&to=&when=&got_car=1&name=&email=&phone=&details=&posted" class="adress">As - BrasÃlia, Brasilia - Distrito Federal, Brazil</a>
</li>
<li>
<a href="addtrip?from=As,%205753%20Deurne,%20The%20Netherlands&to=&when=&got_car=1&name=&email=&phone=&details=&posted" class="adress">As, 5753 Deurne, The Netherlands</a>
</li>
</ul>
</div>
</div>
<label for="to">Till</label>
<input value="" title="Ort, gata eller kommun" name="to" id="to" class="field to help input_error" type="text">
<div class="spacer">
<div class="error">
<p>Var ska du?</p>
</div>
</div>
<label for="when">När</label>
<div class="jdpicker_w">
<input value="" title="YYYY-MM-DD" name="when" id="when" class="field when input_error" type="text">
<div class="date_selector">
<div class="nav">
<div class="error_msg"></div>
<p class="month_nav">
<span class="button prev" title="[Page-Up]">«</span>
<span class="month_name">November</span>
<span class="button next" title="[Page-Down]">»</span>
</p>
<p class="year_nav">
<span class="button prev" title="[Ctrl+Page-Up]">«</span>
<span class="year_name" id="year_name">2010</span>
<span class="button next" title="[Ctrl+Page-Down]">»</span>
</p>
</div>
</div>
</div>
<div class="spacer">
<div class="error">
<p>När vill du åka?</p>
</div>