簡體   English   中英

jQuery 過濾器在 Safari 中不起作用

[英]jQuery filter not working in Safari

如果找到與提供的文本匹配,以下代碼會觸發選擇列表的更改。 它適用於 Chrome、Firefox,但不適用於 Safari:

$("#mySelectList option").filter(function () {
  return this.text == 'some text';
}).attr('selected', true).trigger("change");

當我調試時,this.text 是未定義的。

  • jQuery 版本 2.1.3
  • Safari 桌面版 9.0.1 (Mac)

有任何想法嗎? 提前致謝!

正如您所指出的,這可能是因為.text屬性未定義。

您應該訪問this.textContent$(this).text()

$("#mySelectList option").filter(function () {
  return this.textContent == 'some text';
}).attr('selected', true).trigger("change");

或者

$("#mySelectList option").filter(function () {
  return $(this).text() == 'some text';
}).attr('selected', true).trigger("change");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM