我的网站使用jQuery 1.4.2。问题是.replaceWith()不适用于IE6 & IE7中的jQuery 1.4.2。是否有IE6 & IE7在jQuery 1.4.2中支持的替代方法?
小提琴在这里:http://jsfiddle.net/8CEwf/1/
我知道,似乎jQuery并没有附加到它,但是如果您查看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>');
});发布于 2011-12-20 02:26:42
$("element").after("text to replace element with").remove();示例。
我们只需选择要替换的元素,在其后面添加一些文本,然后从DOM中删除它。
假设这是为了在您的网站上添加一个“添加到购物车”的功能,并且所有的输入都有类似的src属性,那么为什么不给它们添加一个类来简化选择呢?
发布于 2014-01-16 08:58:32
这是另一个诡计。可以在替换之前清空元素。
$(document).ready(function(){
$(selector).empty().replaceWith('...');
});发布于 2011-12-20 02:36:31
这是PHP函数的直接JS实现,应该满足您的需要。
https://stackoverflow.com/questions/8570084
复制相似问题