js取得图片地址,高度,宽度函数
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js取得图片地址,高度,宽度函数</title>
<script>
var width = '';
var height = '';re = /src=(["']?)([sS]*?)(1)/i;
var matches = re.exec(attributes);
if(matches != null) {
var src = matches[2];
} else {
return '';
}re = /widths?:s?(d{1,4})(px)?/ig;
var matches = re.exec(attributes);
if(matches != null) {
width = matches[1];
}re = /heights?:s?(d{1,4})(px)?/ig;
var matches = re.exec(attributes);
if(matches != null) {
height = matches[1];
}if(!width || !height) {
re = /width=(["']?)(d+)(1)/i;
var matches = re.exec(attributes);
if(matches != null) {
width = matches[2];
}re = /height=(["']?)(d+)(1)/i;
var matches = re.exec(attributes);
if(matches != null) {
height = matches[2];
}
}
</script>
</head>
<body>
这段js取得图片地址,高度,宽度函数是一示用正则表达式获取给定字符串里面图片的所有参数,有高宽度等。
</body>
</html>