EasyUI Forum

General Category => General Discussion => Topic started by: catpaw on April 29, 2015, 07:14:27 PM



Title: append onclick nothing happens
Post by: catpaw on April 29, 2015, 07:14:27 PM
hello everybody

In a dialog I have a button , which in the onclick event, I 'm trying to create a searchbox and linkbutton:

Code:
<div id="dlg" class="easyui-dialog">
   <a href="#" id="new" class="easyui-linkbutton" data-options="iconCls:'icon-add'">Add</a>
   <div id="wrapper"></div>
</div>

so in the jquery code:

Code:
$(document).ready(function() {		
    var max_fields = 3;
    var wrapper = $("#wrapper");
    var add_button = $("#new");
   
    var x = 0;
    $(add_button).click(function(e){
        e.preventDefault();
        if(x < max_fields){
            x++;
            $(wrapper).append('<div><input class="easyui-searchbox" data-options="prompt:'Search',searcher:doSearch" name="mytext[]" /><a href="#" class="easyui-linkbutton remove_field" data-options="iconCls:'icon-cancel'"></a></div>');
        }
    });
   
    $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
        e.preventDefault(); $(this).parent('div').remove(); x--;
    })
});

but when I click nothing happens

why?


Title: Re: append onclick nothing happens
Post by: stworthy on April 29, 2015, 11:18:08 PM
Please use the code below instead.
Code:
$(document).ready(function() {    
      var max_fields  = 3;
      var wrapper = $("#wrapper");
      var add_button  = $("#new");
   
      var x = 0;
      $(add_button).click(function(e){
          e.preventDefault();
          if(x < max_fields){
              x++;
              var div = $('<div class="mc-inner"></div>').appendTo(wrapper);
              var input = $('<input>').appendTo(div).searchbox({
                prompt:'Search',
                name:'mytext[]',
                searcher: function(){}
              });
              var btn = $('<a href="#"></a>').appendTo(div).linkbutton({
                iconCls:'icon-cancel',
                onClick:function(){
                  $(this).closest('.mc-inner').remove();
                  x--;
                }
              });
          }
      });
});


Title: Re: append onclick nothing happens
Post by: catpaw on April 30, 2015, 06:45:45 AM
awesome stworthy!!!

Works perfect

Im very thankful