js取得图片地址,高度,宽度函数

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>

时间: 2024-08-01 20:45:50

js取得图片地址,高度,宽度函数的相关文章

js image() 图片自动缩减宽度大小

js image() 图片自动缩减宽度大小 image()对象,然后将希望预装载的图片url传递给此对象.假设我们拥有一个名为heavyimagefile.jpg的图片文件,我们希望当定义图片自动缩减宽度大小,防止撑破 flag=false function drawimage(imgd){  var image=new image();  image.src=imgd.src;  if(image.width>0 && image.height>0){   flag=true

图片路径 js-关于js引用图片地址的问题

问题描述 关于js引用图片地址的问题 目前的html文件所在目录是D:microadeployindex.html但我想引用D:weiappdeploy201505a.png图片的地址,请问各位大神我是应该在index.html中如何填写a.png的图片地址才能保证我能引用到呢?(不要建议文件夹放在一起,因为特殊原因不能放在一起..) 解决方案 将图片映射到IIS,然后就可以在html里面直接引用了.或者用DW等软件选择图片,会生成file...这样的引用代码. 解决方案二: <img src=

js控制iframe的高度/宽度让其自适应内容

 这篇文章主要介绍了如何使用js控制iframe的高度/宽度让其自适应内容,需要的朋友可以参考下  代码如下: <mce:script language= "Javascript "><!--    window.onload=function()  {  parent.document.all("iframe1").style.height = document.body.scrollHeight;  parent.document.all(&q

ASP取出HTML里面的图片地址的实用函数

函数 以下是取出HTML里面的图片地址的函数: 主要原理就是用正则判断 <img> 的<src>属性.这在采集程序中将非常有用. 函数如下: Function ShowPic(str)  Set objRegExp = New Regexp'设置配置对象   objRegExp.IgnoreCase = True'忽略大小写   objRegExp.Global = True'设置为全文搜索   objRegExp.Pattern = "<img.+?>&qu

js/jquery获取容器高度宽度代码

我们在js获取容器高度与宽度都是如下  代码如下 复制代码 <div id='div' style='width:20px;'></div> <script type='text/javascript'> alert(document.getElementById('div').style.width); //return 20px alert(document.getElementById('div').style.height); //return 空 </s

js控制iframe的高度/宽度让其自适应内容_javascript技巧

复制代码 代码如下: <mce:script language= "Javascript "><!-- window.onload=function() { parent.document.all("iframe1").style.height = document.body.scrollHeight; parent.document.all("iframe1").style.width = document.body.scro

js/jquery快速获得图片真实的宽度和高度

CSS帮助设计师设置一个元素的最大宽度max-width和最大高度max-height,防止布局错位,我总是把img, iframe, 和 embed 标签设置成 max-width: 100% 这样在小屏幕的设备上依然可以浏览,不过我还是希望能够获取到图像没有被拉伸和缩小的原始尺寸. The JavaScript 使用一些JavaScript的监听函数,我们可以得到的图像的实际尺寸:  代码如下 复制代码 myImage.addEventListener('onload', function(

js和jquery如何获取图片真实的宽度和高度_javascript技巧

1.什么时候需要获取图片真实的宽度和高度 在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式! 另外一种就是在手机页面上,在新闻页插入的图片往往都是按照图片的原尺寸来展示,如果手机屏幕太小,太大的图就会超出去!这时候有两种解决办法 1)给所有的图片加上这样的样式 1 复制代码 代码如下: .news img{margin:5px auto; display:block;width:100%; height:auto;} 但是这种方式有另外

如何通过js和jquery获取图片真实的宽度和高度

原文:如何通过js和jquery获取图片真实的宽度和高度 1.什么时候需要获取图片真实的宽度和高度       在做pc网页的时候,有时候会考虑按照插入的图片的尺寸来判断图片是横图还是竖图.然后判断过后给予不同的展示方式!       另外一种就是在手机页面上,在新闻页插入的图片往往都是按照图片的原尺寸来展示,如果手机屏幕太小,太大的图就会超出去!这时候有两种解决办法 1)给所有的图片加上这样的样式 .news img{margin:5px auto; display:block;width:1