如何发送带有多个按钮的gwsocket请求?

时间:2019-04-15 11:58:07

标签: javascript jquery

我正在尝试使用多个按钮发送套接字。我想避免很多声明,而是应用一个Class。 我试图使用onclick方法按钮没有成功。

<head>
    script for jquery, dojo .....

    <script type="text/javascript"> 
        require(["dojo/ready"], function(ready){
            ready(function(){

                ... socket onopen, onmessage etc.

                $('#CommSend').onclick = function(e) {
                    var val = dijit.byId('CommandInput').get("value");
                    SendComm(val);
                }; 

                function SendComm(val){
                    socket.send(val);
                    $('#Messages').innerHTML += '\rSent: '+ val;
                    val = '';
                };
                ....
            });
        });
    </script>

    <script type="text/javascript"> 
        $('.ButtonEdit').onclick = function(e) {
            SendComm($(this).attr('id'));
        }; 
    </script>
</head>

<body>
    ..
    <input type="text" id="CommandInput">
    ......
    <input type="button" id="CommSend"></input>
    <input type="button" id="CommInit" class="ButtonEdit"></input>
    <input type="button" id="CommBoot" class="ButtonEdit"></input>
    ....
    </body>

只有“ CommSend”有效。我希望为每个单击的按钮发送带有“ id”的套接字。有什么解决办法吗?

0 个答案:

没有答案