用Javascript调用函数
Calling a Function in Javascript
我已经声明了一个函数,用于在jQuery 中显示对话框
<script type="text/javascript">
function showDialog(str,strtitle)
{
if(!strtitle) strtitle='Error message';
$('#dialog').dialog('destroy');
$('#dialog').show();
$('#dialog').html(str);
$("#dialog").dialog({
resizable: false,
width: 400,
color: '#BF5E04',
open: function () {
$(this).parents(".ui-dialog:first").find(".ui-dialog
titlebar").addClass("ui-state-error");},
buttons: {"Ok": function() {
$(this).dialog("close"); }},
overlay: { opacity: 0.2, background: "cyan" },title:strtitle});}
</script>
我在另一个javascript代码中调用这个函数:
<script type="text/javascript">
var myFile = document.getElementById('myfile');
//binds to onchange event of the input field
myFile.addEventListener('change', function() {
//this.files[0].size gets the size of your file.
var size = this.files[0].size;
document.write(showDialog('size','File Size Exceeds'));
});
</script>
当我执行该函数时,它会写"未定义,为什么对话框没有显示"。第一个功能是头部倾斜,第二个功能是身体部分倾斜。
document.write()
正在写入showDialog()
返回的内容。由于该函数没有返回任何内容,因此它将写入Undefined
。
document.write()不是必需的,只需调用showDialog()即可。
showDialog()函数中没有返回任何值。
只要去掉document.write()
,showDialog()
就不会返回任何内容,因此会出现未定义的错误。
<script type="text/javascript">
var myFile = document.getElementById('myfile');
//binds to onchange event of the input field
myFile.addEventListener('change', function() {
//this.files[0].size gets the size of your file.
var size = this.files[0].size;
showDialog('size','File Size Exceeds');
});
</script>
相关文章:
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 在输入字段上有两个函数调用,一个在Blur上,一个不在Angular中
- 如何在Javascript函数调用中循环变量
- Javascript:应为赋值或函数调用,但实际看到的却是表达式
- 如何远程检查JavaScript应用程序的函数调用堆栈
- javascript函数调用不起作用
- 为什么这个函数调用会破坏程序并导致未定义的变量
- 如何通过函数调用设置图像的src
- 从全局函数调用Ember控制器上的方法
- 为什么Jquery$.ajax在函数调用中触发所有statusCode,即使调用成功
- JavaScript函数调用(arg1)(arg2)
- 打印链接时,将javascript函数调用到链接中
- 在函数调用中封装数据除了隐藏数据之外还有什么优点
- 无法从JavaScript中的函数调用对象属性
- 对中的函数调用进行排序是回调的唯一方法
- 函数调用方法有什么用
- Javascript:JSHint:应为赋值或函数调用,但实际看到的却是表达式
- HTML5(Bootstrap)通过函数调用运行动画
- 函数调用不起作用
- 函数中的Javascript函数调用