首页 > 代码库 > 常用JQuery示例
常用JQuery示例
1.单选按钮
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>js24.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="jquery/jquery-3.2.1.min.js"></script> <script type="text/javascript" src="test.js"></script> </head> <body> <div> <input type="radio" name="sex" value="M" checked>男<br> <input type="radio" name="sex" value="F">女<br> </div> <input type="button" value="click me" onclick="Invoice.test();"> </body> </html>
test.js
;(function(window, document, undefined) { var Invoice = {}; Invoice.test = function () { //定义一个对象接收页面传过来的属性 var params = new Object(); //取到的值不是男或女,而是M或F,我理解是value属性的值 params.sex = $("input[name=‘sex‘]:checked").val(); alert("性别:" + params.sex) }; window.Invoice = Invoice; })(window, document);
2.下拉列表
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>js24.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="jquery/jquery-3.2.1.min.js"></script> <script type="text/javascript" src="test.js"></script> </head> <body> <div> <select id="carType"> <option value="Volvo">Volvo</option> <option value="Saab">Saab</option> <option value="Opel">Opel</option> <option value="Audi">Audi</option> </select> </div> <input type="button" value="click me" onclick="Invoice.test();"> </body> </html>
test.js
;(function(window, document, undefined) { var Invoice = {}; Invoice.test = function () { var params = new Object(); params.status = $("#carType").val(); alert("车型 : " + params.status) }; window.Invoice = Invoice; })(window, document);
常用JQuery示例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。