简体   繁体   English

jQuery .replaceWith不起作用

[英]jQuery .replaceWith Not Working

Google Blogger uses javascript to place a quickedit icon for the admin on widgets or editable areas. Google Blogger使用javascript将管理员的quickedit图标放置在小部件或可编辑区域上。

This is the HTML: 这是HTML:

<a class="quickedit" href="xxxxxx" onclick="return _WidgetManager._PopupConfig(document.getElementById(&quot;BlogArchive1&quot;));" target="configBlogArchive1" title="Edit">
<img alt="" height="18" src="http://img1.blogblog.com/img/icon18_wrench_allbkg.png" width="18">
</a>

I'm trying to replace that image with a Font Awesome Icon. 我正在尝试用“真棒字体”图标替换该图像。 Here is the jQuery that I used: 这是我使用的jQuery:

$('a.quickedit img').replaceWith('<i class="icon-wrench"></i>');

The original image is still there, there are no related errors in the console.log, so why is it not working? 原始映像仍然存在,console.log中没有相关的错误,那么为什么它不起作用? BTW, I am using the $(document).ready function, and version 1.7.1. 顺便说一句,我正在使用$(document).ready函数和版本1.7.1。

EDIT: I also noticed that using this breaks all of my other jQuery scripts on the page. 编辑:我还注意到,使用此方法会破坏页面上所有其他jQuery脚本。 So there may be a conflict. 因此可能存在冲突。

Here is everything without the script I'm trying to add: 这里是没有我要添加的脚本的所有内容:

<script type='text/javascript'>
  $(document).ready(function() {
    $(&quot;.menu-toggle&quot;).click(function (e) {
        $(this).next(&#39;ul&#39;).slideToggle(&quot;fast&quot;);
    });
    $(&quot;#LinkList1 ul li&quot;).click(function (e) {
        $(this).find(&#39;ul&#39;).slideToggle(&quot;fast&quot;);
    });
    $(&quot;body a, .camera_prev, .camera_next, .camera_pag li&quot;).hover(function(){
        link_audio.play();
    },
    function(){
        link_audio.load();
    });
    $(window).scroll(function(){
        if ($(this).scrollTop() &gt; 100) {
            $(&#39;.scrollup&#39;).fadeIn();
        } 
        else {
            $(&#39;.scrollup&#39;).fadeOut();
        }
    }); 
    $(&#39;.scrollup&#39;).click(function(){
        $(&quot;html, body&quot;).animate({ scrollTop: 0 }, 600);
        return false;
    });
  });
</script>

EDIT AGAIN : No matter what I try, it seems all other scripts break and no longer function with no visual errors or errors in the console.log. 再次编辑 :无论我如何尝试,似乎所有其他脚本都中断了,并且不再起作用,没有视觉错误或console.log中的错误。 View the template/site in question here: http://xarpixels-revitalize-template.blogspot.com/ 在此处查看有问题的模板/网站: http : //xarpixels-revitalize-template.blogspot.com/

FYI, only the admin can even see the .quickedit icon. 仅供参考,只有管理员才能看到.quickedit图标。

You can try alternate way. 您可以尝试其他方法。 Like this : 像这样 :

$('a.quickedit img').after('<i class="icon-wrench"></i>').remove();

Hope this helps.. 希望这可以帮助..

As i did not understand the requirement fully, but with others understanding, i have fixed the code, please have a look at this 由于我没有完全理解需求,但是在其他人的理解下,我已经修复了代码,请看一下

Fiddle Demo 小提琴演示

change in css and js code 更改CSS和JS代码

$('a.quickedit').append('<i class="icon-wrench"></i>');

Mark as correct, if it fixed your problem 标记为正确,如果它解决了您的问题

Add this in your CSS class. 将此添加到您的CSS类中。 You need it because the tag i is an inline HTML element. 您需要它,因为标记i是内联HTML元素。 Check this out http://jsfiddle.net/r3GgM/ 看看这个http://jsfiddle.net/r3GgM/

    .icon-wrench{
     ...
    display:block;
    width: xxxx;
    height: nnnn;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM