Dojo js Select和onchange函数

ckx4rj1h  于 2022-12-16  发布在  Dojo
关注(0)|答案(2)|浏览(232)

我正在使用dojo.js来制作具有滚动功能的下拉框,这不是标准select语句所固有的。
我已经成功地创建了下拉菜单,但是使用select语句的标准onchange属性执行函数时遇到了困难。在本例中,onchange =“updateData()”。
感谢任何帮助。

<html>
    <head>
    <title>drop down</title>
    <link rel="stylesheet" href="d3/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="d3/d3.js"></script>
    <script>dojoConfig = {async: true}; </script>
<script src='d3/dojo/dojo.js'></script>  
<script src='d3/dijit/dijit.js' ></script> 

    <script> 

var djConfig = {
    isDebug: true}; </script>

    <script type="text/javascript">
require(["dojo/widget/Select"]);</script> 

    <script> 

require(["dojo/parser"], function(parser) {
parser.parse();});
    </script>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">

    <style>                                        
        #dropdown{

            font-size: 22px;
            font-family:  serif;
            color: grey;}
                   </style>



</head>
<body>

<div class="claro">
        <select 
 id="dropdown" data-dojo-type="dijit/form/Select" data-dojo-props="maxHeight:50" 
 style="width: 100px" onchange= "updateData()" >

            <option value="A">A</option>
            <option value="B">B</option>
            <option value="C">C</option>
        </select>
    </div>         

 <script type="text/javascript">

 //The following is used to reset the dropdown box to original value on pg refresh
 document.getElementById("dropdown").selectedIndex = 0;

字符串
函数updateData(){alert(“你好”)}

</script>

 </body>
 </html>
ttcibm8c

ttcibm8c1#

var dropDown = new Select({
               name: "select2",
               id: "projectDropDown",
               onChange: function (value) 
               {
                 //console.log("project Id: ", this.get("value"))
                 reScopeProjectContext(value,satpcontext);
               },
               store: projectStore,
               labelAttr: "name",
               value: projectInContext,
               }).placeAt(win.body()).startup();
n3schb8v

n3schb8v2#

updatedata函数是在声明select小部件之后定义的。这将不起作用
请尝试下面的代码。

<!DOCTYPE html>
<html>
<head>
    <link href="dojo/dojo-release-1.9.3-src/dijit/themes/claro/claro.css" rel="stylesheet"/>
    <script type="text/javascript">
        dojoConfig = {
            async: true,
            parseOnLoad: true
        };
    </script>
    <script type="text/javascript" src="dojo/dojo-release-1.9.3-src/dojo/dojo.js"></script>
    <script type="text/javascript">
        require(["dojo/parser", "dijit/form/Select"],function(parser){
            parser.parse();

        });
        function updateData(){
            alert("Onchange function called");
        }

    </script>
</head>
<body class="claro">
<select name="select1" data-dojo-type="dijit/form/Select" onchange="updateData()">
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
</select>
</body>
</html>

相关问题