English | 正體中文 | 简体中文

Jquery ui droppable accept



范例程式码 Expand
<!-- Javascript -->
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
    $(function () {
        $(".square").draggable();
        $("#CarsParkinglot").droppable({
            accept: "#car",
            drop: function (event, ui) {
                $(this).css("background-color", "lightgreen")
            },
            out: function (event, ui) {
                $(this).css("background-color", "")
            }
        });
        $("#MotocyclesParkinglot").droppable({
            accept: "#motocycle",
            drop: function (event, ui) {
                $(this).css("background-color", "lightgreen")
            },
            out: function (event, ui) {
                $(this).css("background-color", "")
            }
        });
    });
</script>

<!-- HTML -->
<style>
    .square {
  		width:100px;
        height:100px;
        border:1px solid black;         
        margin-bottom:5px;
        margin-left:5px;
        text-align:center;        
  		line-height:100px;
        float:left;
        background-color:lightblue;
        cursor:pointer;
    }
  
  	.squaredotted{
  		width:150px;
        height:150px;
        border:1px dotted gray;         
        margin-bottom:5px;
        margin-left:5px;
        text-align:center;
        line-height:150px;
        float:left;
    }
</style>
<div style="margin-bottom:10px;">Drag and drop car to 'Cars only', motocycle to 'Motocycles only'</div>
<div style="float:left">
    <div id="car" class="square">Car</div>          	
</div>
<div style="float:left">
    <div id="motocycle" class="square">Motocycle</div>          	
</div>
<div style="float:left;margin-left:50px;">
    <div id="CarsParkinglot" class="squaredotted">Cars only</div> 
  	<div id="infoCars"></div>
</div>
<div style="float:left;margin-left:50px;">
    <div id="MotocyclesParkinglot" class="squaredotted">Motocycles only</div> 
  	<div id="infoMotocycles"></div>
</div>

    
在线测试程序
© 2012 PureExample.com contact