解决方案 »
- 简易购物车 数量乘以价格 为什么没有结果?
- 一个JS语法,菜鸟求问,谢谢
- 用JQuery动态替换网页元素?
- 上海500强企业诚聘开发LEADER 3名
- xmlHttp.responseText是字符串吗?
- javascript + css 下拉菜单在IE7上的不兼容问题。
- 发布用于JavaScript调试的小工具(jsTrace)
- asp.net 用了jquery-easyui后不能引发服务器事件了
- 关于getSelection()的问题
- for循环读取json生成的HTML,怎么将添加的HTML分别添加点击事件实现效果图的效果(具体麻烦大神们看看代码和截图))
- firebug 怎么查看JScript.js文件里的变量
- <a>如何实现 点击复制<a>中的链接地址
$("#temp img").each( function() {
if ($(this).width > 625) $(this).width = 625;
});
$("#temp img").each(function(){
if($(this).width()>625){
$(this).attr("width","625");
//$(this).width(625);
}
});
$("#temp img").each( function() {
if (!$(this).parent().is('a')) $(this).wrap("<a></a>");
});
$("#temp p:has(img)").remove();
不过我总结了一下,结合新需求,主要代码如下:/*
此程序想要达到的文本修改效果
1.外围没有包裹a的img增加a元素(a中有如下属性:rel=shadowbox,href=img的src)
2.子元素包含img的a,属性修改为(rel=shadowbox,href=被包含img的src)
3.img的alt属性改为“点击查看大图”
4.如果p的子元素是img,则把p换成div
5.如果img width<=625,则不改,如果img width>625,则width=625*/
$("#add").click(function(){ $("#temp").html($("#src").val()); //process functions
//1
$("#temp img").each( function() {
//5
if($(this).width()>625){
$(this).attr("width","625");
} //4 step 1
if($(this).parent().is("p")){
$(this).wrap("<div></div>");
}
}); //4 step 2
$("#temp div").each(function(){
if($(this).parent().is("p")){
$(this).parent().after($(this));
//$(this).parent().remove();
}
});
//4 step 3
$("#temp p:empty").remove(); //1
$("#temp img").each( function() {
if (!$(this).parent().is("a")){
$(this).wrap("<a></a>");
}
});
//2
$("#temp a").has("img").attr("rel","shadowbox");
$("#temp a").has("img").each(function(){
this.href=$(this).children("img").attr("src")
}); //3
$("#temp img").attr("alt","点击查看大图"); $("#opt").text($("#temp").html()); $("#temp").empty();
}
);
此程序想要达到的文本修改效果
1.外围没有包裹a的img增加a元素(a中有如下属性:rel=shadowbox,href=img的src)
2.子元素包含img的a,属性修改为(rel=shadowbox,href=被包含img的src)
3.img的alt属性改为“点击查看大图”
4.如果p的子元素是img,则把p换成div
5.如果img width<=625,则不改,如果img width>625,则width=625*/