用js取图片高度来控制div的高度

JavaScript049

用js取图片高度来控制div的高度,第1张

alert(["图片大小是:",img.width,img.height])

用js或者jquery设置div的高度为img.height

$("div").css("hight",img.height.width)

如果问题解决,请点赞采纳!!!

给html的实现,.net中,把$("#InvestXMYQ")改成$("#<%=InvestXMYQ.ClientID%>")

<!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">

<head>

<title></title>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<script src="js/jquery-1.4.4.js" type="text/javascript"></script>

<script>

$(document).ready(function(){

$("#add").click(function(){

var rows = $("#InvestXMYQ").attr("rows") + 2

$("#InvestXMYQ").attr("rows",rows)

})

$("#delete").click(function(){

var rows = $("#InvestXMYQ").attr("rows") - 2

if(rows>3){

$("#InvestXMYQ").attr("rows",rows)

}

})

})

</script>

</head>

<body>

<div><div id="add">+</div>   <div id="delete">-</div></div>

<textarea name="InvestXMYQ" rows="5" id="InvestXMYQ"></textarea>

</body>

</html>