How to create a radio button dynamically with jQuery?

后端 未结 8 1035
南方客
南方客 2020-12-08 22:25

I am developing a small application in which I want to create 20 radio buttons in one row.

How can I do this using jQuery?

相关标签:
8条回答
  • 2020-12-08 22:55

    This code will append radio buttons with unique id to each of them....

    for (var i=0;i<=20;i++)
    {
     $("#yourcontainer").append("<input type='radio' id='myRadio"+i+"'>")
    }
    
    0 讨论(0)
  • 2020-12-08 22:56

    for (i = 0; i < 20; i++) {
        $('<input type="radio" name="radiobtn" >Yourtext'+i+'</input>').appendTo('#container');
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="container"></div>

    0 讨论(0)
提交回复
热议问题