[英]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 是未定義的。
有任何想法嗎? 提前致謝!
正如您所指出的,這可能是因為.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.