How to disable only certain links on JSP using jQuery
I have been using a loop on JSP to call three different Struts actions but print the same parameters of data:
<a href="customize_business?method=add&listingId=<%=biz.getListingId()%>&bid=<%=bid `%>&source=<%=biz.getSource()%>" class="ajax-link-add" id="addBus"><img` `src="../images/green-tick.png" /></a>
My jQuery is:
$(function() {
$('.ajax-link-add').click( function() {
alert("in jquery fro add");
$.get( $(this).attr('href'), function(msg) {
if (msg!=null) {
alert($.getAnchorValue('source', $('#addBus').attr('href')));
$('#addBus').fadeTo('slow', 0.5, function() {
$('#addBus').removeAttr("href");
});
}
});
return false;
});
});
So output will be:
CitySearch Mexican Village Restaurant 'a link to save in db' 'a link to delete from db' Yelp Mexican Village Restaurant 'a link to save in db' 'a link to delete from db' YahooLocal Mexican Village Restaurant 'a link to save in db' 'a link to delete from db'
Once a user clicks to save business name in CitySearch, all other records of Ciysearch should get greyedout and links disabled. But all records and links of Yelp and YahooLocal should be active for user to select one from each.
My current jQuery disables all records (Yelp,Citysearch,yahoolocal) and all links even if user clicks on any one link within any one source. I need him to select only one business on all 3 sources.
How should I change my jQuery? Thanks.
@Shadow: Thankyou. It worked and only links in one loop for one source get disabled. Each link has a 'check' and 'cross' to add and delete business from database. Once the user checks a business on a particular source, all add/delete links for that source get disabled using above code. But I want to keep only one delete link active, for user to be able to delete the selected business.
<a href="customize_business?method=add&listingId=<%=biz.getListingId()%>&bid=<%=bid `%>&source=<%=biz.getSource()%>" class="ajax-link-add" id="addBus" source="`<%=biz.getSource()%>"><img src="../images/green-tick.png" /></a> <a href="customize_business?method=delete&listingId=<%=biz.getListingId()%>&bid=<%=bid %>&source=<%=biz.getSource()%>" class="ajax-link-delete" id="deleteBus" source="<%=biz.getSource()%>"><img src="../images/red-cross.png" /></a>`
Jquery is:
$(function() {
$('.ajax-link-add').click( function() {
var oLink = $(this);
$.get( $(this).attr('href'), function(msg) {
if (msg != null) {
alert($.getAnchorValue('source', oLink.attr('href')));
$("a[source='" + oLink.attr("source") + "']").fadeTo('slow', 0.5, function() {
$("a[source='" + oLink.attr("source") + "']").removeAttr("href");
});
}
});
return false;
});
});
$(function() {
$('.ajax-link-delete').click( function() {
alert("in jquery fro add");
var oLink = $(this);
$.get( $(this).attr('href'), function(msg) {
if (msg != null) {
alert("in here 1 ");
alert($.getAnchorValue('source', oLink.attr('href')));
$("a[source='" + oLink.attr("source") + "']").fadeTo('slow', 0.5, function() {
$("a[source='" + oLink.attr("source") + "']").removeAttr("href");
});
}
});
return false;
});
});
yes....so if I have
Source: Citysearch
Mexican Village Restaurant add delete
Mexican Town Restaurant add delete
Chinese Restaurant add delete
Source: Yelp
Mexican Village Restaurant add delete
Mexican Town Restaurant add delete
Chinese Restaurant add delete
Once user clicks on 'add' for CitySearch: Mexican Village Restaurant, all other records of only CitySearch should get grayed out with their links to add/delete disabled. Just the link to 'delete' of CitySearch: Mexican Village Restaurant should be active and enabled for user to delete that record from db and select some other business. When user selects other business, same thing should happen. Other businesses disabled and grayed out but link to delete for that particular chosen business should be active.
Meanwhile, all add/delete links on Yelp and othe开发者_Go百科r sources should be active.
You need to reference the active element only:
alert("in jquery fro add");
var oLink = $(this);
$.get( $(this).attr('href'), function(msg) {
if (msg != null) {
alert($.getAnchorValue('source', oLink.attr('href')));
oLink.fadeTo('slow', 0.5, function() {
oLink.removeAttr("href");
});
}
});
return false;
Edit: to disable only certain group of links, first add the source
as custom attribute:
<a href="customize_business?method=add&listingId=<%=biz.getListingId()%>&bid=<%=bid `%>&source=<%=biz.getSource()%>" class="ajax-link-add" id="addBus" source="<%=biz.getSource()%>">
Then change the code to:
oLink.fadeTo('slow', 0.5, function() {
$("a[source='" + oLink.attr("source") + "']").removeAttr("href");
});
精彩评论