js動態生成勾選框,可單選可多選

1、動態生成的位置,html代碼:

<body>
    <div class="show" id="show">
 
    </div>
</body>

2、這是ajax()的一部分,從數據庫取得所需的數據
success : function(data, textStatus) {
            $("#loading").hide();
            if(data.code == 20000) {
                var i = 0;
                saveRightidList = data.rightidList;
                for(var j = 0; j < data.rightidList.length; ++j){
                    genShowContent("show", data.rightidList[j], data.descriptionList[j], "right");

                    for(var nb= data.descriptionList[j].length;nb< 15;nb++) {
                        $("#show").append(" ");//每個<input>之間保證不緊挨着
                    }
                    if( j %4 ==3 ) {$("#show").append("<br/>");}//進行換行
                }
            }
        }

3、生成

function genShowContent(id, rid, text, key) {
    var checkText = "radio";
   var showContent = "<input type='"+ checkText +"' value ='"+ rid + "'id= '" + key+rid + "'/>" + text ;//多選
var showContent = "<input name='rolelist' type='"+ checkText +"' value ='"+ rid + "'id= '" + key+rid + "'/>" + text;//單選 $("#" + id).append(showContent);

}

4、多選效果圖




5、單選效果圖怎麼傳不上去了······單選的效果和多選的類似

6、最後再隨便寫寫

$(document).ready(function(){})可以簡寫成$(function(){});
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章