1

我们如何增加或减少 div 在 btn click in asp.net 的大小?

样式表

<style>
div{
    width:50px; 
    height:70px; 
    float:left; 
    margin:5px; 
    background:rgb(255,140,0); 
}
</style>

Javascript:

<script src="_http://code.jquery.com/jquery-latest.js"></script>
<script>
$("div").one('click', function () {
    $(this).height(30);
});
</script>

标记:

<body>
    <div></div>
</body>
4

3 回答 3

0

HTML

<div id="div1"></div>
<input type="button" id="aAdd"  value="Increase" />
<input type="button" id="aDecrease"  value="Decrease" />

脚本

var currentHeight;
var measurement=100;

$(function(){    
    currentHeight=$("#div1").height();  
    $("#aAdd").click(function(){      
        currentHeight=parseInt(currentHeight)+measurement    
        $("#div1").height(currentHeight);
    });
     $("#aDecrease").click(function(){     
        currentHeight=parseInt(currentHeight)-measurement             
        $("#div1").height(currentHeight);
    });

});

这是工作示例http://jsfiddle.net/pJWMh/14/

于 2012-04-04T13:23:37.557 回答
0
$("div").click(function() { $(this).height(30); });

请参阅工作 jsFiddle 演示

于 2012-04-04T13:13:46.467 回答
-2

你所有的拳头都给了 div 的 id。我修改了一些 html 并放置按钮,如下所示。

<body>
<form id="form1" runat="server">
<div id="dvMain">
</div>

<input id="btn" onclick="javascript:changeDivSize();" type="button" value="Change Size" />

</form>

调用 javascript functin changeDivSize() 如下

function changeDivSize() {

        $("#dvMain").height(500);
    }

希望对你有帮助...

于 2012-04-04T12:50:43.470 回答