如何使用按钮在对话框上显示 Javascript 函数的结果
How to show the result of a Javascript Function on a Dialog using a Button?
我的问题是如何使用按钮在对话框上显示Javascript函数的结果?
泰为你帮忙!
Javascript
function yourfunction()
{
// code
return result;
}
.HTML
<button onclick="alert(yourfunction());">Click</button>
演示
function myfunction()
{
return "It works";
}
<button onclick="alert(myfunction())">Clic</button>
你可以尝试使用 jQuery UI 对话框:
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>
像这样:
.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/
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 正在全局范围中查找JavaScript函数
- 如何将输入(type=text)从html表单传递到javascript函数
- 如何调用这个匿名 JavaScript 函数
- 通过Ajax将JavaScript函数传递给PHP文件
- 在javascript函数中设置全局变量
- 如何在执行此特定onclick事件时执行JavaScript函数
- 使用javascript函数在页面初始化后加载jquery
- javascript函数同步
- 如何将一个JavaScript函数回调为多个函数
- 在javascript函数中使用php变量
- 代码背后调用一个JavaScript函数的按钮点击-C#
- 将JavaScript函数与HTML分离
- 组合两个javascript函数
- 在 Java 中的 JavaScript 函数中插入 Wicket 值
- javascript函数内部的代码用逗号而不是分号分隔
- href属性内的javascript函数
- 使用html表单中的参数调用JavaScript函数
- 分析Javascript函数中的多个对象
- javascript函数的:和=之间的区别