js取得圖片位址,高度,寬度函數
<html xmlns="HTTP://www.jzread.com/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>