0

当我单击按钮时,它必须显示对话框,但它没有显示。我从 dojo 文档中找到了这段代码。当我单击按钮时,它没有显示任何内容。这是我的代码,请帮助我。

<script type="text/javascript">
dojo.require("dijit.form.Form");
dojo.require("dijit.Dialog");
dojo.require("dijit.form.Button");
dojo.require("dojo.parser");
dojo.require("dijit.form.TextBox");

</script>

<body class="claro">
<div id="gridDiv"></div>

 <div data-dojo-type="dijit.Dialog" id="formDialog2"
    title="Filtering Rows" style="display: none">
    <form data-dojo-type="dijit.form.Form" id="123">
        <script type="dojo/event" data-dojo-event="onSubmit"
            data-dojo-args="e">

              require(["dojo/dom"], function(dom){
        var f = dojo.byId("123");
        var s = "";
            var elem = f.elements[0];
            s = elem.value;
 dijit.byId('grid').filterBar(s);

    });
   return false;

    </script>
        Search: <input type="text" name="searchtext" value=""
data-dojo-type="dijit/form/TextBox">
        <div class="dijitDialogPaneActionBar">
            <button data-dojo-type="dijit.form.Button" type="submit">OK</button>
            <button data-dojo-type="dijit.form.Button" type="button"
data-dojo-props="onClick:function(){dijit.byId('formDialog2').hide();}">Cancel</button>
        </div>
    </form>
</div>

<button id="buttonThree" data-dojo-type="dijit.form.Button"
    type="button">
    Show Filter
    <script type="dojo/method" data-dojo-event="onClick"
        data-dojo-args="evt">
    dijit.byId("formDialog2").show();
</script>
</button> 

4

2 回答 2

0

检查你是否有

require(["dijit/Dialog",'dijit/form/TextBox','dijit/form/Button']); 

在头部某处添加。当我添加它时,它工作正常。

http://jsfiddle.net/theinnkeeper/HX4uR/

于 2013-10-03T14:19:11.487 回答
0

看来您的道场根本没有加载。为了避免解析问题,我总是在 djConfig="parseOnLoad:true为最新版本的 dojo 调用脚本时导入 dojo 库。

 dojo.require("dijit.form.Form");
 dojo.require("dijit.Dialog");
 dojo.require("dijit.form.Button");
 dojo.require("dojo.parser");
 dojo.require("dijit.form.TextBox");
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.6.2/dojo/resources/dojo.css" rel="stylesheet" />
<link href="http://ajax.googleapis.com/ajax/libs/dojo/1.6.2/dijit/themes/claro/claro.css" rel="stylesheet" />
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js" djConfig="parseOnLoad:true"></script>

<body class="claro">
  <div id="gridDiv"></div>

  <div data-dojo-type="dijit.Dialog" id="formDialog2" title="Filtering Rows" style="display: none">
    <form data-dojo-type="dijit.form.Form" id="123">
      <script type="dojo/event" data-dojo-event="onSubmit" data-dojo-args="e">

        require(["dojo/dom"], function(dom){ var f = dojo.byId("123"); var s = ""; var elem = f.elements[0]; s = elem.value; dijit.byId('grid').filterBar(s); }); return false;

      </script>
      Search:
      <input type="text" name="searchtext" value="" data-dojo-type="dijit/form/TextBox">
      <div class="dijitDialogPaneActionBar">
        <button data-dojo-type="dijit.form.Button" type="submit">OK</button>
        <button data-dojo-type="dijit.form.Button" type="button" data-dojo-props="onClick:function(){dijit.byId('formDialog2').hide();}">Cancel</button>
      </div>
    </form>
  </div>

  <button id="buttonThree" data-dojo-type="dijit.form.Button" type="button">
    Show Filter
    <script type="dojo/method" data-dojo-event="onClick" data-dojo-args="evt">
      dijit.byId("formDialog2").show();
    </script>
  </button>


</body>

</html>

于 2015-03-31T19:48:14.377 回答