JS获取图片大小(长宽)问题
<scriptlanguage="javascript">functioninsertTitle(tValue){vart1=tValue.lastIndexOf("\\...
<script language="javascript">
function insertTitle(tValue){
var t1 = tValue.lastIndexOf("\\");
var t2 = tValue.lastIndexOf(".");
if(t1 >= 0 && t1 < t2 && t1 < tValue.length){
document.getElementById("pTitle").value = tValue;
document.getElementById("pTitlel").value = tValue.substring(t1 +1);}
}
</script><form2 action="" method="get" onSubmit="return false;">
<input type="text" name="pTitle"><input type="text" name="pTitlel">
<input type="file" name="pFile" onChange="if(this.value)insertTitle(this.value);">
<input type="submit" value="submit">
</form2>以上可以传回了图片的本地路径和文件名,我现在需要传回图片长、宽(分别传回文本框),JS代码该如何修改才能分别获取图片长宽? 展开
function insertTitle(tValue){
var t1 = tValue.lastIndexOf("\\");
var t2 = tValue.lastIndexOf(".");
if(t1 >= 0 && t1 < t2 && t1 < tValue.length){
document.getElementById("pTitle").value = tValue;
document.getElementById("pTitlel").value = tValue.substring(t1 +1);}
}
</script><form2 action="" method="get" onSubmit="return false;">
<input type="text" name="pTitle"><input type="text" name="pTitlel">
<input type="file" name="pFile" onChange="if(this.value)insertTitle(this.value);">
<input type="submit" value="submit">
</form2>以上可以传回了图片的本地路径和文件名,我现在需要传回图片长、宽(分别传回文本框),JS代码该如何修改才能分别获取图片长宽? 展开
2个回答
2013-04-10
展开全部
可以配合JS来实现获到本地磁盘图片文件的相关属性,请参照天南(QQ:46926125)提供的DEMO: ##Code##
<script language="javascript">
function insertTitle(tValue){
var t1 = tValue.lastIndexOf("\\");
var t2 = tValue.lastIndexOf(".");
if(t1 >= 0 && t1 < t2 && t1 < tValue.length){
document.getElementById("pTitle").value = tValue;
document.getElementById("pTitlel").value = tValue.substring(t1 +1);
document.getElementById('guo').innerHTML="<img id='demo_img' src='"+tValue+"' />"
document.getElementById('imgc_width').value=document.getElementById('demo_img').width;
document.getElementById('imgc_height').value=document.getElementById('demo_img').height;
}
}
</script>
<form action="" method="get" onSubmit="return false;">
<input type="text" name="pTitle">
<input type="text" name="pTitlel">
<input type="file" name="pFile" onChange="if(this.value){insertTitle(this.value)};">
<input type="submit" value="submit">
</form>
图片宽:<input type="text" id="imgc_width" />px
图片高:<input type="text" id="imgc_height" />px
<hr />
<div id="guo"></div>
<script language="javascript">
function insertTitle(tValue){
var t1 = tValue.lastIndexOf("\\");
var t2 = tValue.lastIndexOf(".");
if(t1 >= 0 && t1 < t2 && t1 < tValue.length){
document.getElementById("pTitle").value = tValue;
document.getElementById("pTitlel").value = tValue.substring(t1 +1);
document.getElementById('guo').innerHTML="<img id='demo_img' src='"+tValue+"' />"
document.getElementById('imgc_width').value=document.getElementById('demo_img').width;
document.getElementById('imgc_height').value=document.getElementById('demo_img').height;
}
}
</script>
<form action="" method="get" onSubmit="return false;">
<input type="text" name="pTitle">
<input type="text" name="pTitlel">
<input type="file" name="pFile" onChange="if(this.value){insertTitle(this.value)};">
<input type="submit" value="submit">
</form>
图片宽:<input type="text" id="imgc_width" />px
图片高:<input type="text" id="imgc_height" />px
<hr />
<div id="guo"></div>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询