jQuery.replaceWith()替换

jQuery.replaceWith()替换,jquery,internet-explorer-7,replace,internet-explorer-6,replacewith,Jquery,Internet Explorer 7,Replace,Internet Explorer 6,Replacewith,我的站点使用jQuery 1.4.2。问题是,.replaceWith()在jQuery 1.4.2的IE6和IE7中不起作用。jQuery 1.4.2中是否有IE6和IE7支持的替代方法 小提琴在这里: 我知道,jQuery似乎没有附加到它,但如果您查看HTML,jQuery就在那里,因为JSFIDLE不提供1.4.2版 HTML: 脚本: $(document).ready(function(){ $('img[src="/v/vspfiles/templates/cyberfront/

我的站点使用jQuery 1.4.2。问题是,
.replaceWith()
在jQuery 1.4.2的IE6和IE7中不起作用。jQuery 1.4.2中是否有IE6和IE7支持的替代方法

小提琴在这里:

我知道,jQuery似乎没有附加到它,但如果您查看HTML,jQuery就在那里,因为JSFIDLE不提供1.4.2版

HTML:


脚本:

$(document).ready(function(){
$('img[src="/v/vspfiles/templates/cyberfront/images/buttons/btn_addtocart_small.gif"]').replaceWith('<br /><span id="blackbutton" class="mediumbutton" style="display:block;">Add to Cart</span>');
$('input[src="/v/vspfiles/templates/cyberfront/images/buttons/btn_go_gray.gif"]').replaceWith('<input type="submit" class="graybutton smallbutton" name="Go" alt="Go" value="Go" title="Go">');
$('img[src="/v/vspfiles/templates/cyberfront/images/Bullet_MoreInfo.gif"]').replaceWith('<span class="learnmore">Learn More</span>');
});
$(文档).ready(函数(){
$('img[src=“/v/vspfiles/templates/cyberfront/images/buttons/btn_addtocart\u small.gif“])。替换为('
添加到购物车'); $('input[src=“/v/vspfiles/templates/cyberfront/images/buttons/btn_go_gray.gif”]”)。替换为(“”); $('img[src=“/v/vspfiles/templates/cyberfront/images/Bullet\u MoreInfo.gif“])。替换为('Learn More'); });

我们只需选择要替换的元素,在其后面添加一些文本,然后将其从DOM中删除


假设这是针对您网站上的“添加到购物车”功能,并且所有输入都将具有类似的
src
属性,那么为什么不向它们添加一个类以简化选择呢?

这是一个PHP函数的直接JS实现,应该满足您的需要


还有一个窍门。可以在替换之前清空元素

$(document).ready(function(){
     $(selector).empty().replaceWith('...');
});

为了完成这个简单的任务,这是一个完全不必要的措施。@user1090389这不是PHP,而是JS。它是PHP函数的JS版本。Purmou,当然它是不必要的,但它仍然有效,只是建议了一个替代的解决方案。这是JavaScript已经存在的字符串的一个功能要弱得多的版本。replace:(无法修改核心页面…这就是为什么我要克服整个障碍的原因。谢谢。jQuery在这方面做得太多了。
$("element").after("text to replace element with").remove();
$(document).ready(function(){
     $(selector).empty().replaceWith('...');
});