代码如下,我想在class="test"里面的内容每个图片src的地址前加上一个网址比如:src="www.csdn.net/Public/images/bottom1.jpg"><SCRIPT type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></SCRIPT>
<title>无标题文档</title>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$("img").each(function () { //这里不能只用img,因为我网页里面还有其它的图片的,只以这个来历遍的话就不行了。
//alert($(this).attr("src"))
});
});
});
</script>
</head>
<body>
<button>SRC加上网址</button>
<div class="test">
<LI class=li_1><IMG alt="" src="Public/images/bottom1.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom3.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom2.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom4.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom5.jpg"></LI>
<LI class=li_3><IMG alt="" src="Public/images/bottom6.jpg"></LI>
</div>
</body>
</html>
<title>无标题文档</title>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$("img").each(function () { //这里不能只用img,因为我网页里面还有其它的图片的,只以这个来历遍的话就不行了。
//alert($(this).attr("src"))
});
});
});
</script>
</head>
<body>
<button>SRC加上网址</button>
<div class="test">
<LI class=li_1><IMG alt="" src="Public/images/bottom1.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom3.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom2.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom4.jpg"></LI>
<LI class=li_2><IMG alt="" src="Public/images/bottom5.jpg"></LI>
<LI class=li_3><IMG alt="" src="Public/images/bottom6.jpg"></LI>
</div>
</body>
</html>
解决方案 »
- 动态的添加Ext TabPanel时,为什么它的html不能直接显示,要点击一下才显示
- js中有让Date对象的时间+1分钟的方法吗
- 请问如何使用Javascript实现添加新的记录到Select选框里面
- js动态div定位问题 。
- 关于showModalDialog窗口的问题
- 如何比较两个时间的大小?
- 想到头晕都不知道怎样实现,帮帮忙~~高手!
- 如何在Netscape 7.0中使用Javascript添加ActiveX控件!!!急!!!!
- 自动提交表单
- 新手想关注下github
- 请问safari浏览器 在windows和mac系统下运行有什么不同的地方吗?
- 各位大侠,我想把百度地图放到我公司的网上来,怎么弄呀,难不难?
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
$(".test li img").each(function(){
var stringObj=this.src
$(this).attr("src",stringObj.replace(/Public/, "www.csdn.net/Public"));
});
});
});
</script>
但如果你想增加后可以指向其他的网站的话,就需要做点小改动
$("button").click(function () {
$(".test li img").each(function(){
var _src=$(this).attr("src");
$(this).attr("src","http://www.csdn.net/"+_src);
});
});