我試圖讓每個.vehicleID
的CID
並追加每個href
的.vehicle-actions
類中有&VID=[CID]
jQuery的改變每個循環中的各子環節
<ul>
<li><a href="./garage_vehicle.php?mode=add_vehicle"><span>Create a Vehicle</span></a></li>
<li class="vehicle-view toggleVehicleButton"><a class="vehicleID" href="./garage_vehicle.php?mode=view_own_vehicle&CID=6"><span>2014 Audi A4</span></a>
<div class="vehicle-actions" style="width: 179px; display: none;">
<ul>
<li><a href="/board/garage_vehicle.php?mode=view_vehicle">View Vehicle</a></li>
<li><a href="/board/garage_vehicle.php?mode=edit_vehicle">Edit Vehicle</a></li>
<li><a class="deletevehicle" href="">Delete Vehicle</a></li>
<li><a href="/board/garage_modification.php?mode=add_modification">Add Modification</a></li>
<li><a href="/board/garage_premium.php?mode=add_premium">Add Insurance</a></li>
<li><a href="/board/garage_quartermile.php?mode=add_quartermile">Add Quartermile Time</a></li>
<li><a href="/board/garage_dynorun.php?mode=add_dynorun">Add Dynorun</a></li>
<li><a href="/board/garage_track.php?mode=add_lap">Add Lap</a></li>
<li><a href="/board/garage_service.php?mode=add_service">Add Service</a></li>
<li><a href="/board/garage_vehicle.php?mode=view_own_vehicle">Set Main Vehicle</a></li>
</ul>
</div>
</li>
<li class="vehicle-view toggleVehicleButton"><a class="vehicleID" href="./garage_vehicle.php?mode=view_own_vehicle&CID=7"><span>2008 Chevrolet Corvette</span></a>
<div class="vehicle-actions" style="width: 179px;">
<ul>
<li><a href="/board/garage_vehicle.php?mode=view_vehicle">View Vehicle</a></li>
<li><a href="/board/garage_vehicle.php?mode=edit_vehicle">Edit Vehicle</a></li>
<li><a class="deletevehicle" href="">Delete Vehicle</a></li>
<li><a href="/board/garage_modification.php?mode=add_modification">Add Modification</a></li>
<li><a href="/board/garage_premium.php?mode=add_premium">Add Insurance</a></li>
<li><a href="/board/garage_quartermile.php?mode=add_quartermile">Add Quartermile Time</a></li>
<li><a href="/board/garage_dynorun.php?mode=add_dynorun">Add Dynorun</a></li>
<li><a href="/board/garage_track.php?mode=add_lap">Add Lap</a></li>
<li><a href="/board/garage_service.php?mode=add_service">Add Service</a></li>
<li><a href="/board/garage_vehicle.php?mode=view_own_vehicle">Set Main Vehicle</a></li>
</ul>
</div>
</li>
</ul>
在我的頭上,似乎簡單,但我可以」不像是會抓住我做錯了什麼
jQuery的
function getURLParameter(url, name) {
return (RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1];
}
$('.vehicleID').each(function(i, val){
var vehicleIDurl = ($(this).attr('href'));
var CID = getURLParameter(vehicleIDurl, 'CID');
$('.vehicle-actions',this).each(function(i, val){
editCID = $(this).find('a');
editCID.attr('href', editCID.attr('href') + '&VID=' + CID);
});
});
http://jsfiddle.net/Beardyco/dmSRd/1/仍然遇到問題的網址 – ngplayground
你看到什麼問題? –