How do I modify this jQuery :submit selector example?
Looking at this jQuery example, how can I modify the 开发者_高级运维code so that it only changes the color of the cell if the value of the submit button in that cell is a certain value.
i.e.-
var submitEl = $("td :submit")
//Only do the below if the submit buttons value is "XYZ"
.parent('td')
.css({background:"yellow", border:"3px red solid"})
$("td input[value='SomeValue']:submit")
var submitEl = $('td :submit').filter(function() { return $(this).val() == "certain"; });
You can check for the value in the selector, but it may lead to quoting headaches (depending on the value) and also it may not be quite as fast (though that's rarely a serious concern).
you need a each loop I think this is what your trying to do
$("td :submit").each(function(){
if ($(this).val()== "XYZ"){
$(this).parent('td').css({background:"yellow", border:"3px red solid"});
}
});
EDIT
using better selector eliminates if statment
$("td:submit[value='XYZ']").each(function(){
$(this).parent('td').css({background:"yellow", border:"3px red solid"});
});"
select only the elements that have the value you want:
var submitEl = $("td :submit[value='XYZ']")
精彩评论