我的頁面上有iFrame
(id = iframe1)內部的img
標籤。 他們中的一些已經src
屬性設置爲myimg.jpg
, 'myimg_small.jpg',myimg_large.jpg
等通過屬性的部分值查找元素
我想在裏面找#iframe1
一切與src
像myimg
,所以我寫了
images = $('#iframe1').contents().find('[src*="myimg"]')
但我得到如下錯誤
Uncaught Error: Syntax error, unrecognized expression: [src*="myimg"])
at Function.Sizzle.error (jquery-1.8.2.js:4679)
at tokenize (jquery-1.8.2.js:4739)
at select (jquery-1.8.2.js:5099)
at select (jquery-1.8.2.js:5276)
at Function.Sizzle [as find] (jquery-1.8.2.js:3941)
at init.find (jquery-1.8.2.js:5372)
at <anonymous>:1:36
這裏有什麼問題?
更新
alert($('#if').contents().find('[src*="ss"]').next().html());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe id='if'>
<img src='sss.jpg' />
<div>
scdscd
</div>
</iframe>
你可以創建一個我們可以調試的示例嗎? – Rajesh
你在那裏有一個額外的右括號。 – Enfyve
您的JSFiddle代碼無效HTML - iFrame代碼內部的代碼不會奇蹟般地變成iFrame內容 - 我在這裏將代碼添加爲一個''''''代碼段。請閱讀https://developer.mozilla.org/en/docs/Web/HTML/Element/iframe – mplungjan