首页
极刻
圈子
教程
开源
登录 / 注册
返回教程:jQuery 教程
TRY RUN / 在线示例
jQuery 教程 尝试一下
jQuery 教程 尝试一下
源代码
运行
<!DOCTYPE html> <html> <head> <script src="//libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $(".field").change(function(){ $(this).css("background-color","#D6D6FF"); }); }); </script> </head> <body> <p>Attach a function to run when an element has been changed:</p> Enter your name: <input class="field" type="text"> <p>Write something in the input field, and then press enter or click outside the field.</p> <p>Car: <select class="field" name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> </p> <p>Select an option in the drop-down list.</p> </body> </html>
运行结果