<script>
$(function() {
$( ".target" ).change(function() { alert( "Handler for .change() called." ); }); }); </script>
<form> <input class="target" type="text" value="Field 1"> <select class="target"> <option value="option1" selected="selected">Option 1</option> <option value="option2">Option 2</option> </select> </form> <div id="other"> Trigger the handler </div> </body>
<style> div { color: red; } </style> <link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.10.2.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> </head> <body> <select name="sweets" multiple="multiple"> <option>Chocolate</option> <option selected="selected">Candy</option> <option value='aaa'>Taffy</option> <option selected="selected">Caramel</option> <option>Fudge</option> <option>Cookie</option> </select> <div></div> <script> $( "select" ) .change(function () { var str = ""; $( "select option:selected" ).each(function() { str += $(this).val()+$( this ).text() + " "; }); $( "div" ).text( str ); }) .change(); </script> </html>
|