Display all items in array using jquery

后端 未结 6 1357
悲&欢浪女
悲&欢浪女 2020-12-04 19:07

I have an array that I want to have displayed in html.. I don\'t want to write multiple lines for posting each item in the array but all should be exactly the same. ie

6条回答
  •  时光取名叫无心
    2020-12-04 19:26

    here is solution, i create a text field to dynamic add new items in array my html code is

     
    	 
    		

    now type any thing in text field and click on button this will add item onto array and call function dispaly_arry

    $(document).ready(function()
    {		
    	function display_array()
    	{
    		$("#names").text('');
    		$.each(names,function(index,value)
    		{
    		  $('#names').append(value + '
    '); }); } var names = ['Alex','Billi','Dale']; display_array(); $('#btn').click(function() { var name = $('#name').val(); names.push(name);// appending value to arry display_array(); }); });

    showing array elements into div , you can use span but for this solution use same id .!

提交回复
热议问题