Meine Frage ist Wie man das Ergebnis einer Javascript-Funktion auf einem Dialog unter Verwendung eines Knopfes zeigt?Wie zeigt man das Ergebnis einer Javascript-Funktion in einem Dialog mit einem Button an?
Ty für Ihre Hilfe!
Meine Frage ist Wie man das Ergebnis einer Javascript-Funktion auf einem Dialog unter Verwendung eines Knopfes zeigt?Wie zeigt man das Ergebnis einer Javascript-Funktion in einem Dialog mit einem Button an?
Ty für Ihre Hilfe!
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>
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>
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());
});