【问题标题】:jquery variable substitutionjquery变量替换
【发布时间】:2012-03-29 16:33:44
【问题描述】:

这行得通..

$("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();

【问题讨论】:

  • 这是 javascript,而不是 php...这些类型的文本替换甚至不适用。您需要手动插入字符串。

标签: javascript jquery string-concatenation


【解决方案1】:

你想要这个:

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

【讨论】:

  • 效果很好.. 但为什么不这样:$("select[title='Third Choice'] option[value='1']").after($("").attr("value","5").text("+ what +"));
  • @cyberpine:在该代码 sn-p 中,您的字符串中有 what。只需:.text(what)
猜你喜欢
  • 2012-02-16
  • 1970-01-01
  • 2013-06-19
  • 2014-10-10
  • 2014-04-18
  • 1970-01-01
  • 2014-07-28
  • 2016-08-15
  • 1970-01-01
相关资源
最近更新 更多