展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>通用方法测试</title>
</head>
<body>
<script>
function getImgName(str){
var reg1 = /(\<img)(.*(?=(src\s*?=\s*?["'])([^"^']*)["']))/gim;
str.match(reg1);//配置表达式
str = RegExp.$4;
var array=str.split("/");//切割
if(array.length>0){
str=array[array.length-1];
}
var array=str.split(".");//切割
if(array.length>1){
//array.splice(0,1);//删除元素
array.splice(array.length-1,1);
}
str=array.join('.');
return str;
}
var str0= "<img src='a.bbbc.jpg' >";
var str1= '<img src="http://news.163.com/sports/yao.b.jpg" >';
var str2= '<img src="a.bbbc.jpg" >';
document.write(getImgName(str0));
document.write("<br>");
document.write(getImgName(str1));
document.write("<br>");
document.write(getImgName(str2));
</script>
</body>
</html>
展开全部
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script src="../Scripts/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
var img = document.getElementById("x");
var src = img.getAttribute("src");
alert(src.substring(0,src.lastIndexOf(".")));
});
</script>
</head>
<body>
<img id="x" src="a.jpg" alt="" />
</body>
</html>
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询