javascript - 使用 src 链接获取 Img 元素

标签 javascript jquery html

我在“IFRAME”中收集了“img”标签。

i have to get the specified img element using src value

 <iframe class="k-conent">
    <html>
    <body>
    <img src="http://localhost:59023/ImageBrowser/GetImageData?path=download.jpg&amp;companyId=50c2ca58-4036-4f0b-9a15-a3b000df6980" alt=""><img src="http://localhost:59023/ImageBrowser/GetImageData?path=itm_2013-04-23_09-56-06_1.jpg&amp;companyId=50c2ca58-4036-4f0b-9a15-a3b000df6980" alt=""><br _moz_dirty="true">
    </body>
    </html>
    </iframe>

我当前的实现是这样的:

var findalbelsrcvalue="http://localhost:59023/ImageBrowser/GetImageData?Path=download.jpg;companyId=50c2ca58-4036-4f0b-9a15-a3b000df6980"
     var $content = $('.k-content').contents();
            var $body = $content.find('body');
            var $imagetag = $content.find('img');
            if ($imagetag.length > 0) {
                $imagetag.each(function() {
if($(this).attr("src")==findalbelsrcvalue){
                    var width = $('txtWidth').val();
                    var height = $('txtWidth').val();
            switch ($("input[name=Alignment]:checked").val()) {
                case "Left":
                    $(this).css('float', 'left');
                case "Middle":
                    $(this).css('display', 'block');
                    $(this).css('margin-left', 'auto');
                    $(this).css('margin-right', 'auto');
                case "Right":
                    $(this).css('float', 'right');
                    break;
                default:
                    break;
            }
}
           });
    }

它对我有用,但它循环了每个 img 标签。它没有任何意义。任何人都可以帮助我如何找到 img 标签。

Like

`var element=$("srclink").contents().find("img");`

最佳答案

var element=$("img[src='<src-value>']");

关于javascript - 使用 src 链接获取 Img 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30122271/

相关文章:

jquery - <a href ="xyz.php"> 的目标到 php 页面上的特定 div,而不重定向 php 页面

javascript - 使用 JQuery 附加带有样式的 div

javascript - 从 div 动态获取 iFrame 代码

javascript - 跨浏览器jquery

javascript - jQuery动画让页面跳转到顶部

javascript - 如何为我的评论制作滚动内容?

javascript - 我可以在使用phonegap的Android应用程序中使用目录选择器吗?

javascript - 强制进行不正确的比较以在 JavaScript 中抛出警告/错误

javascript - 我的 JS 文件中的 HTML - 意外 token < 在 loadash.js 的第 1 行

html - 在 html 页面上向下滚动时如何阻止白色出现?