jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jQuery .replaceWith()替代大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的网站使用jQuery 1.4.2.问题是.replaceWith()在IE6& jQuery 1.4.2中的IE7. IE6&是否支持其他方法? jQuery 1.4.2中的IE7?

小提琴在这里http://jsfiddle.net/8CEwf/1/

我知道,似乎jQuery没有附加到它,但是如果你看一下HTML,jQuery就在那里,因为jsfiddle没有提供1.4.2版本

HTML:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<img src="/v/vspfiles/templates/cyberfront/images/buttons/btn_addtocart_small.gif">
<input type="image" src="/v/vspfiles/templates/cyberfront/images/buttons/btn_go_gray.gif">
<img src="/v/vspfiles/templates/cyberfront/images/Bullet_MoreInfo.gif">

脚本:

$(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>');
});

解决方法

$("element").after("text to replace element with").remove();

Example.

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

假设这是用于您网站上的“添加到购物车”功能,并且所有输入都具有类似的src属性,那么为什么不只是为它们添加一个类以使选择更容易?

大佬总结

以上是大佬教程为你收集整理的jQuery .replaceWith()替代全部内容,希望文章能够帮你解决jQuery .replaceWith()替代所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: