jquery - Call javascript function multiple times -
Therefore, I have some problems finding a way to solve this problem. I know that it is silly , But I'm really stuck on this.
I have something like this:
& lt; Div class = "tdate" & gt; Sat October 11 01:11:01 +0000 2014 & lt; / Div & gt; & Lt; Div class = "tdate" & gt; Sat October 11 01:10:44 +0000 2014 & lt; / Div & gt; & Lt; Div class = "tdate" & gt; Sat October 11 00:51:03 +0000 2014 & lt; / Div & gt; and this javascript function:
function parser date (tdate) {var system_date = new date (date.ps (tdate)); Var user_date = new date (); If (K.E.) {system_date = Date.parse (tdate.replace (/ (\ +) /, 'UTC $ 1')}} var diff = Math.floor ((user_date - system_date) / 1000); If (diff & lt; 20) {return diff + "seconds ago";} (diff & lt; 40) {return "half minute first"; } If (difference and LT; 60) {"less than a minute ago";} (diff & lt; = 90) {return "one minute ago";} (diff & lt; = 3540) {return Math. Round (diff if (diff & lt; = 86400) {return Math diff / 3600} + "hours ago" (return) = "minutes ago";} (diff & lt; = 5400) {back "1 hour ago"; };} (Diff & lt; = 129600) {return "1 day ago";} if (diff & lt; 604800) {return mathematics. (Diff / 86400) + "day ago";} If (diff & lt; = 777600) {return "1 week ago";} "back to" + system_date;} Var = Funk (): (A.match (/ MSIE \ s ([^;] *) /)}} (); I Trying to do something is to convert all the formats into a new format (which is my javascript). But I do not know how to call this function to change all the different changes. If I use parseTwitterDate ("Sat Oct 11 00:51:03 +0000 2014"), this will work, but only once.
Actually, I want to see all the dates on my page format: "Saturn Oct 11 01:11:01 +0000 2014" Changes: "47 minutes ago" (or whatever is produced) . But I do not know how the function parseTwitterDate (tdate) is called.
Sorry for my very bad explanation. Let me know if I do not clarify myself.
And thank you very much for anyone who can help me.
Thanks a lot! :)
Since you are using JQuery (or at least JQuery tags are used You can
$ (function () {$ ('.tdate') Html (parseTwitterDate (($ (value) .html ())))}}}}}; & lt; script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" & Gt; & lt; / script> & lt; div class = "tdate" & gt; Sat Oct 11 01:11:01 +0000 2014 & lt; / div & gt; & lt; div class = "tdate" & gt; Saturn Oct 11 01:10:44 +0000 2014 Sat Oct 11 00:51:03 +0000 2014 < / Code>
Comments
Post a Comment