简体   繁体   中英

jQuery src selector Issue

I'm doing a poker game. I have an issue about a jQuery selector.

$('[src$='+a+']').replaceWith('<img src="images/backcard.png" width = 118, height = 166, border=3, style = "border-color: #FFFFFF;" />');    

It tells me Error: Syntax error, unrecognized expression: [src$=♠6.jpg]

Here is the code :

function CartesJoueur(){
var random1 = " "; // 1ere carte : variable aléatoire sur une même famille (famille ♦ par exemple)
var random2 = " "; // 2eme carte : variable aléatoire sur les symboles (♦ ♣ ♥ ♠)
var random3 = " "; // 1ere carte : variable aléatoire sur une même famille (famille ♦ par exemple)
var random4 = " "; // 2eme carte : variable aléatoire sur les symboles (♦ ♣ ♥ ♠)

random1 = getRandomInt(2, 14); //nombre aléatoire entre 2 et 14
random2 = getRandomInt(2, 14); //nombre aléatoire entre 2 et 14
random3 = getRandomInt(1, 4); //nombre aléatoire entre 1 et 4
random4 = getRandomInt(1, 4); //nombre aléatoire entre 1 et 4

if(random3 === 1)
    var string1 = "images/♠" + random1 + ".jpg";
else if(random3 === 2)
    var string1 = "images/♣" + random1 + ".jpg";
else if(random3 === 3)
    var string1 = "images/♦" + random1 + ".jpg";
else if(random3 === 4)
    var string1 = "images/♥" + random1 + ".jpg";

if(random4 === 1)
    var string2 = "images/♠" + random2 + ".jpg";
else if(random4 === 2)
    var string2 = "images/♣" + random2 + ".jpg";
else if(random4 === 3)
    var string2 = "images/♦" + random2 + ".jpg";
else if(random4 === 4)
    var string2 = "images/♥" + random2 + ".jpg";

//permet d'éviter d'avoir deux fois la même image
if(random3 === random4 && random1 === random2)
{
    random2 = getRandomInt(2, 14);
    random4 = getRandomInt(1, 4);
}

//affichage des deux images 
$('#6row').after('<img src=' + string1 + ' width = 118, height = 166, border=3, style = "border-color: #FFFFFF;" />');
$('#6row').after('<img src=' + string2 + ' width = 118, height = 166, border=3, style = "border-color: #FFFFFF;" />');
// console.log("hey " + random1 + " " + random3); // DEBUG

a =string1.substring(7);
console.log(a);

$('[src$='+a+']').replaceWith('<img src="images/backcard.png" width = 118, height = 166, border=3, style = "border-color: #FFFFFF;" />');

}    

Could you tell me what i must modify in the selector ?

Thanks !

mr rogers solves OP's problem:

Maybe too simple, but have you tried adding quotes? Following from your example in the comments, $('[src$="'+a+'"]') with quotes around the inserted string. – mr rogers Dec 30 '14 at 3:50

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM