Home > Web Front-end > JS Tutorial > JavaScript uses Ajax to dynamically load CheckBox check boxes

JavaScript uses Ajax to dynamically load CheckBox check boxes

巴扎黑
Release: 2017-09-01 10:21:12
Original
1611 people have browsed it

本文通过实例代码给大家介绍了JavaScript 通过Ajax 动态加载CheckBox复选框的方法,需要的朋友参考下吧

废话不多说了,直接给大家贴代码了,具体代码如下所示:

<html>
 <head></head>
 <body>
  <pre name="code" class="html">

<p class="controls" id="compareyear"> 

</p>



//动态加载年份checkbox by dongch 20170830 function GetCompareYearByStationName(name) { var str = " "; $.ajax({ type: "GET", //默认是GET url: '@Url.Action("*********", "*****")', data: "stationName=" + name, async: false, //同步 cache: false, //不加载缓存 success: function (obj) {//后台传来的数据:"2010,2011,2012,2013,2014,2015" var yearArray = new Array(); yearArray = obj.split(","); for (var i = 0; i < yearArray.length; i++) { if (i < yearArray.length - 3) { str += " "; } else {//后三个年份默认选中 str += " "; } } $("#compareyear").html(str); }, error: function () { alert("对比年限加载失败"); } }); }
 
  
 
 
Copy after login

The above is the detailed content of JavaScript uses Ajax to dynamically load CheckBox check boxes. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template