接上:http://www.cnblogs.com/akou/p/4461557.htmljavascript
代碼:html
13.獲取選中的下拉框java
<!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../../scripts/jquery.js" type="text/javascript"></script> </head> <body> <input type="button" id="send1" value="get" onclick="getObj()"/> <select id="someElement"> <option>一班</option> <option>二班</option> <option>三班</option> </select> <script> function getObj(){ var $obj = $('#someElement').find('option:selected'); alert( $obj.val() ); } </script> </body> </html>
14.獲取選中的下拉框jquery
<!DOCTYPE> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../../scripts/jquery.js" type="text/javascript"></script> </head> <body> <button >toggle</button> <input type="checkbox" value="1" />籃球 <input type="checkbox" value="2" />足球 <input type="checkbox" value="3" />羽毛球 <script> var tog = false; $('button').click(function(){ $("input[type=checkbox]").attr("checked",!tog); tog = !tog; }); </script> </body> </html>
15.使用siblings()來選擇同輩元素ui
<!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../../scripts/jquery.js" type="text/javascript"></script> <style> li.active{ font-size:20px; color:red; } </style> </head> <body> <ul id="nav"> <li>Google</li> <li>百 度</li> <li>新浪</li> </ul> <script> /* 不這樣作 $('#nav li').click(function(){ $('#nav li').removeClass('active'); $(this).addClass('active'); }); */ //替代作法是 $('#nav li').click(function(){ $(this).addClass('active') .siblings().removeClass('active'); }); </script> </body> </html>
16.從元素中除去HTMLthis
<!DOCTYPE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../../scripts/jquery.js" type="text/javascript"></script> </head> <body> <div> <p>鋒利的<a href="#nogo">jQuery</a></p> </div> <script> (function($) { $.fn.stripHtml = function() { var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi; this.each(function() { $(this).html( $(this).html().replace(regexp,'') ); }); return $(this); } })(jQuery); //用法: $('div').stripHtml(); </script> </body> </html>
這些只是一部分,所有的代碼(上)面有連接。spa