jquery 類選擇器獲取值
阿新 • • 發佈:2018-12-31
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="EasyUI-1.5.1-InsdepTheme-1.0.3/jquery.min.js"></script> <script> $(function () { $(".test").click(function () {
//獲取屬性id的值 var val=$(this).attr("id");
//獲取文字值
var text = $(this).text(); alert(val); }) $("#student").click(function () { var val=$(this).attr("name"); alert(val); }) $("input").click(function () { var val=$(this).val(); alert(val) }) }) </script> </head> <body> <a id="user" class="test" href="#">User</a> <a id="admin" class="test" href="#">admin</a> <a id="student" name="Tom" href="#">Student</a> <input id="btn" type="button" name="ok" value="Hello" /> </body> </html>