Wednesday, 15 August 2012

javascript - Jquery return to parent function on button click -


I have a popupdraw like make sure to show as below

< Pre> & lt; Div class = 'pop' & gt; Me & lt; Span class = "spok" & gt; OK & lt; / Span & gt; & Lt; Span class = "spcancel" & gt; Cancel & lt; / Span & gt; & Lt; / Div & gt;

Now this popup will open in some position, and when I click on the button I want to return some values ​​to the original values ​​

button event < / Strong>

  $ (".spok"). Click (function () {return "OK";}); $ (". Spcancel"). Click (function () {return 'CANCEL';});  

Lookup method

  function showpop () {$ ('.pop'). Show (); }  

Called like this

  var retval = showpop () warning;  

But it seems that I am not close to my requirement.

Code on Bella

Update

function call back But .... When I tried to hide the popup, it has been warned several times in the drop down menu, select Yes or No Click OK or Cancel, two or three times, you have the effect Will appear

updated bella

  [Fiddle2] [2]  

Dialogue Operations & amp; Buttons are asynchronous Use the callback to transmit the result (such as the dialog passed) or the event. One way to provide callback to your popup, which is called back with the result:

  function ShowPop (onclows) {$ ('.pop'). Show (); $ (".spok"). Click (function () {onclose ('OK');}); $ (". Spcancel"). Click (function () {onclose ('CANCEL');}); } $ (Document) .ready (function () {var retval = showpop (functional) {warning (retal);}}}});  JSFiddle:   

Note: for the event the event handler should be more specific to the dialog (possibly use representative events instead of popup):

  Function Showpop (Onclos) {$ ('.pop'). Show (). ('Click', 'span', function () {onclose ($ (this) .attr ('class')), // or some other asset of the button}}}}  
< P> More practical examples (using data - attributes):

Jeffield:


No comments:

Post a Comment