JS很简单的问题
点击按钮 "加 "的时候只执行一次xxx().即textarea的高度只增加200.再点击按钮增加高度就没反映了~....怎么样才能每点击一次textarea的高度就在原基础上增加200?
<script>
function xxx()
{
document.getElementById( "xx ").style.height+=200;
}
</script>
<textarea id= "xx "> </textarea>
<input onclick= "xxx() " value= "加 ">
------解决方案-------------------- <script>
function xxx()
{
var i=document.getElementById( "xx ").style.height;
var j=i.split( "px ");
var k=Math.floor(j[0]);
k += 200;
document.getElementById( "xx ").style.height=k;
}
</script>
------解决方案--------------------因为document.getElementById( "xx ").style.height返回的是一个字符串,如(200px)
------解决方案--------------------document.getElementById( "xx ").style.height = parseInt(document.getElementById( "xx ").style.height) + 200 + "px ";
------解决方案-------------------- <script>
function xxx()
{
var hh=document.getElementById( "xx ").style.height;
var h=hh.substring(0,hh.length-2);
var seth=Number(h)+200;
document.getElementById( "xx ").style.height=seth+ "px ";
}
</script>
<textarea id= "xx " style= "height:120px "> </textarea>
<input onclick= "xxx() " value= "加 ">