2012-03-29 7 views
0

この作品..jqueryの変数置換

$("select[title='First Choice'] option[text='hello']").remove(); 

本のバリエーションの数は..私はこれが愚かであるかを知りません。

var what='hello'; 

    $("select[title='First Choice'] option[text=$what]").remove(); 

も試しました。あなたはこの希望

$("select[title='First Choice'] option[text=$(what)]").remove(); 
$("select[title='First Choice'] option[text='$what']").remove(); 
$("select[title='First Choice'] option[text=$what.val()]").remove(); 
+4

これはjavascriptのある、PHPではない...テキスト置換のこれらのタイプにも適用されません。文字列に手動で挿入する必要があります。 – mellamokb

答えて

6

$("select[title='First Choice'] option[text=" + what + "]").remove(); 
+0

はうまく動作しますが、なぜこれはしません:$( "選択[title = 'Third Choice']オプション[value = '1']")。 "、" 5 ")。text(" + what + ")); – o365spo

+0

@cyberpine:そのコードスニペットでは、文字列の中に 'what'があります。ただしてください: '.text(what)' –