我以前问过这个问题,并多次尝试解决它,但都没有成功。
作为一个对javascript几乎没有经验的非程序员,
我想有一个书签或类似的东西,帮助我用原始(全尺寸)图像替换页面上的所有图像,该图像的链接指向。例如,如果我点击链接的图像,它将带我到全尺寸图像,但我希望该全尺寸图像显示在页面上。
下面是一个站点代码的示例:
<a href="http://www.diyphysics.com/wp-content/uploads/2012/02 Multiplier_schematic.jpg">
<img class="aligncenter wp-image-627" title="Multiplier_schematic" src="http://www.diyphysics.com/wp-content/uploads/2012/02/Multiplier_schematic-1024x205.jpg" alt="Schematic of Dual-Polarity High-Voltage Cockroft-Walton Multiplier by David and Shanni Prutchi" width="614" height="123"/>
</a>我希望它是:
<img class="aligncenter wp-image-627" title="Multiplier_schematic" src="http://www.diyphysics.com/wp-content/uploads/2012/02/Multiplier_schematic.jpg" alt="Schematic of Dual-Polarity High-Voltage Cockroft-Walton Multiplier by David and Shanni Prutchi"/>宽度和高度限制已删除。
举个例子,这个网站
http://www.pocketmagic.net/?p=802
有许多小的低分辨率图像显示为链接,我希望书签小程序将所有这些图像替换为它们所指向的高分辨率图像。这样我就可以将页面保存为一个整体,或者将其导出...
谢谢!
编辑: 1. @Frosco,我试过了,但我对JS的了解很少,哪里也去不了。
解决方法:多亏了John,我想通了,
这是JS bookmarklet,如果有人感兴趣的话:
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){$('a img').each(function(index) { var currentElement= $(this); var anchor = currentElement.parent(); var highResSource = anchor.attr("href"); var newImage = "<img src='" + highResSource + "'/>" +"</div>"; anchor.html(newImage);});});发布于 2012-07-05 10:46:31
像这样的东西应该会让你开始:
$('a img').each(function(index) {
var currentElement= $(this);
var anchor = currentElement.parent();
var highResSource = anchor.attr("href");
var newImage = "<img src='" + highResSource + "'/>";
anchor.html(newImage);
});发布于 2012-07-05 10:49:49
你可以试试.unwrap()
$('img').each(function() {
var $this = $(this);
if ($this.attr('src') === $this.parent('a').attr('href')) {
$this.unwrap();
}
});https://stackoverflow.com/questions/11337234
复制相似问题