一个功能我已经声明了一个函数来显示在jQuery的调用Javascript中
<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>
当我执行函数,它写入Undefined,为什么对话框没有显示。第一个功能是在头部,第二个在身体部分。
它的写入定义是因为函数showDialog没有返回任何东西。 document.write()不是必需的,只需调用showDialog()。 – Ivan 2012-04-04 15:47:46
您是否试过通过类似萤火虫的方式运行它?并通过步进,顺便说一句:你的第一个节的第13行 - 是该行打破存在于真正的代码,还是你把它放在使它适合更加整齐? – 2012-04-04 15:49:23
@Ivan是正确的,只是一个加法:直到页面加载您可能要推迟调用'showDialog':'$(的ShowDialog);'。 – DCoder 2012-04-04 15:49:56