本篇内容主要讲解“如何通过jQuery获取input数据及html中name”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何通过jQuery获取input数据及html中name”吧!
在 index.html 下面
可以知道先加载 jquery.min.js,再加载 test.js
而加载到 test.js
但界面加载完成。就运行 init(),这个 init 中调用了绑定函数,绑定了2个按钮。
程序源码如下:
index.html
<html><head><title>Test</title></head><body><div class="group1"> <label >名称1_1</label> <input type="text" name="input1"></input> <br/> <label>名称1_2</label> <input type="text" name="input2"></input> <br/> <label>名称1_3</label> <input type="text" name="input3"></input> <br/> <label>名称1_4</label> <input type="text" name="input4"></input> <br/> <button class="do-btn1">点击</button></div><br/><br/><div class="group2"> <label>名称2_1</label> <input type="text" name="input1"></input> <br/> <label>名称2_2</label> <input type="text" name="input2"></input> <br/> <label>名称2_3</label> <input type="text" name="input3"></input> <br/> <label>名称2_4</label> <input type="text" name="input4"></input> <br/> <button class="do-btn2">点击</button></div></body><script src="jquery.min.js"></script><script src= "test.js"></script></html>
test.js
;var member_do1 = { init: function(){ this.eventBind(); }, eventBind:function(){ $(".group1 .do-btn1").click(function(){ $.ajax({ url: "https://www.baidu.com", type: "POST", data:{ value1:$(".group1 input[name=input1]").val(), value2:$(".group1 input[name=input2]").val(), value3:$(".group1 input[name=input3]").val(), value4:$(".group1 input[name=input4]").val() }, dataType:'json', success:function(res){ console.log(res); } }); }) }};$(document).ready(function(){ member_do1.init(); member_do2.init();});var member_do2 = { init: function(){ this.eventBind(); }, eventBind:function(){ $(".group2 .do-btn2").click(function(){ $.ajax({ url: "https://www.baidu.com", type: "POST", data:{ value1:$(".group2 input[name=input1]").val(), value2:$(".group2 input[name=input2]").val(), value3:$(".group2 input[name=input3]").val(), value4:$(".group2 input[name=input4]").val() }, dataType:'json', success:function(res){ console.log(res); } }); }); }};
到此,相信大家对“如何通过jQuery获取input数据及html中name”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。