【问题标题】:Retrieve <noscript> tag data using javascript使用 javascript 检索 <noscript> 标记数据
【发布时间】:2017-04-21 07:00:22
【问题描述】:

我有这个 &lt;noscript&gt; 标签数据我想通过 javascript / jQuery 检索图像 src 属性数据 我尝试了太多但我无法获取请帮助我获取图像src属性数据

<script>
// Using javascript 
var nos = document.getElementsByTagName("noscript")[0];
var htmlData = nos.innerHTML;
</script>

jQuery(function() {
var data = jQuery("noscript").closest("#anaImg").attr('src');
      alert(data);     
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<noscript>
<p><img src="http://xxxx.xxxxx.com/analytics/conv_tracking.php?idsite=1545" style="border:0;" alt="" id="anaImg"/></p>
</noscript>

【问题讨论】:

    标签: javascript jquery noscript


    【解决方案1】:

    您可以使用隐藏的 div 并将其中的 noscript 标记内容附加为 html

    示例:

    var noscript_text = $("noscript").text();     //get noscript tag content
    $('#noscript').append($(noscript_text));      //append to another div to get the image src
    var get_img_src = $('#anaImg').attr('src');   // get the img src
    var new_img_src = "nothing";                  // type your new img src here
    var replace_img_src = noscript_text.replace(get_img_src,new_img_src); // replace old img src with new one
    $("noscript").text(replace_img_src);          // change the content of no script tag with new src
    alert($("noscript").text());                  // alert the new noscript tag content
    #noscript{
      display: none;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <noscript>
    <p><img src="http://xxxxxxxx.xxxxxxxxxxx.com/analytics/conv_tracking.php?idsite=1545" style="border:0;" alt="" id="anaImg"/></p>
    </noscript>
    
    <div id="noscript"></div>

    注意:请注意#noscript 这是 div 的 ID 和 noscript 这是给noscript 标签

    【讨论】:

    • 但我想在 noscript 中将另一个 url 附加到 src 标记中......请帮助
    • 谢谢@Mohamed-Yousef :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多