Is there something wrong with the code below it just won't work, no errors?
var select_value = $("#cart-image").attr('alt');
if ($("select_value:contain开发者_JAVA百科s('Aqua')")) { keyword = "aqua"; };
While all the other answers are correct, they forget to mention that you can use jQuery for this. There is the Attribute contains selector:
if ($("#cart-image[alt*=Aqua]").length) keyword = "aqua";
You're using jQuery to do something that it is neither designed for nor capable of. Use Javascript's native functions to search strings for substrings:
if (select_value.indexOf('Aqua') > -1) {
keyword = 'aqua';
}
The double quotes are making jQuery interpret the "select_value" as a string, rather than the variable.
try
if (select_value.indexOf('Aqua') != -1) { keyword = "aqua"; };
.attr() returns a string, not a DOM element
精彩评论