E.split not a function error when attaching date as data in jquery
We've got a problem where jquery is giving us an "E.split is not a function" error when we try to attach a date as data to a DOM object.
We are creating our d开发者_如何学Goate as follows:
new_end_date = new Date(start_time_date);
new_end_date.setMinutes(start_time_date.getMinutes() + service_duration);
Then we are using the .data()
function to attach the data to a dive with the id end_time as follows
$("#end_time").data(new_end_date);
According to our reading the .data() function should be able to "attach data of any type to DOM elements" (see: http://api.jquery.com/data)
However it causes the split is not a function error.
It works fine if we replace the date reference with a string so it appears to be related to Jquery's handling of the date object.
Thanks for any assistance you can offer.
The data function expects a key.
$("#end_time").data("enddate", new_end_date);
or an object (with key/value pairs)
$("#end_time").data({ enddate: new_end_date });
Your using .data
wrong. your supposed to store the data under a key. Like
$("#end_time").data("end-date", new_end_date);
Then you can call $("#end_time").data("end-date")
to get that date out again.
精彩评论