Monday 15 June 2015

javascript - Not able to add datepicker to new element -


I'm dynamically adding new form elements using jquery for some reason, call For .datepicker () will not work on the new elements I added, but worked on older people who were not dynamically added if I were .attr ('style', 'color: red ; '); instead of .datepicker () , it works, note that the original call works within the document's prepared work. function addMulti (name) {this = $ ('[name =' + name + ']'); Base = it.data ('baseName'); On = it.data ('number') + 1; Name = base + "-" + on; Copy = it.clone () copy.prop ("name", name) .attr ("data-is-default", false) .removeAttr ('data-number'). Fadein ('slow') appendTo (it.parent ()). It.data ('number', on); If (this .has class ('date-pickable')) {// & lt; - This is true, I checked copy.datepicker (); // If I add clone .attr ('style', 'color: red;') then it turns red color}}

This is the call that date Creates all fields created in the picker:

  & lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("input.date-pickable"). Datepicker ()}); & Lt; / Script & gt;   

There is no error appearing in the firebug or "antant element" cheat in Google Chrome. Although something strange is happening if I type in the document in the same call. Firebug functions in the consul, it will still not create the date picture of the newly added elements. However, if I take the output, then it selects the element that should be targeted.

  $ ("input.date-pickable"). Datepicker () // I typed in the item [input # dp1371953134342.field-input 06/22/2013, input # dp1371953134343.field- input, input # dp1371953134342.field-input 06/22/2013, input # dp1371953134342.field -input 06/22/2013] // Does it exclude the last three digits added to the elements added to JQuery are the IDs specified. I checked it.  

The datepicker of the jQuery UI will always add the class hasDatepicker To avoid having multiple datepickers for the same element near a datepicker in any element.
When you are cloning an element, which is already a datepicker, you can also get that category, and you clone the new detection, like jQuery UI thinks that the element is already a Datepicker

Remove the square from the clone: ​​

  var copy = it.clone (false); ("Data", name) .attr ("data-is-default", "wrong"). RemoveAttr ('data-number'). FadeIn ('slow'). AppendTo (it.parent ());   

And do not try to make all your variables global.

No comments:

Post a Comment