2016-04-27 5 views

Antwort

0

Javascript

function yourfunction() 
{ 
// code 
return result; 
} 

HTML

<button onclick="alert(yourfunction());">Click</button> 

DEMO

function myfunction() 
 
{ 
 
    return "It works"; 
 
}
<button onclick="alert(myfunction())">Clic</button>

0

Sie können versuchen, jQuery UI-Dialog zu verwenden:

function someFunction() { 
 
    return 42; 
 
} 
 

 
$(function() { 
 
    $('<div>' + someFunction() + '</div>').appendTo('body').dialog(); 
 
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
 
<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

-1

So:

HTML

<button id="button"> 
    Show results 
</button> 

JS

// The function whose results we want to print out 
function foo() { 
    var result = "bar"; 
    // we need to return the result 
    return result; 
} 

// get the button in the HTML 
var button = document.getElementById("button"); 

// attach the click event on it 
button.addEventListener("click", function() { 
    // after clicking the button, show the results 
    alert(foo()); 
}); 

https://jsfiddle.net/v39honrp/2/

Verwandte Themen