Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JQuery更改函数中的内容按钮_Jquery_Html - Fatal编程技术网

使用JQuery更改函数中的内容按钮

使用JQuery更改函数中的内容按钮,jquery,html,Jquery,Html,我正在学习JQuery,我不明白为什么当我点击它时内容按钮没有改变。 更改必须从打开切换到关闭,反之亦然。 我从中获取一些代码来制作和处理按钮,但这对我没有帮助。 我的代码有什么问题 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="

我正在学习JQuery,我不明白为什么当我点击它时内容按钮没有改变。 更改必须从打开切换到关闭,反之亦然。 我从中获取一些代码来制作和处理按钮,但这对我没有帮助。 我的代码有什么问题

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="scripts/jquery-1.11.1.min.js"></script>
        <!--script per creare e gestire il contenuto dei bottoni a seconda del loro stato (spento o acceso)-->
        <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>
        <script>
            function invia(num_led, response) {
                jQuery.support.cors = true;     
                // Create Toggle Button.
                $("#jqxButton").jqxToggleButton({ 
                    width: '150', height: '25', toggled: true 
                });
                var toggled = $("#jqxButton").jqxToggleButton('toggled');
                $.ajax ({
                    crossDomain: true,
                    async : true,
                    type: "POST",
                    data: num_led,
                    dataType: "text/html",
                    cache: false,
                    url: "http://ledon.dlinkddns.com",
                    success: function( r ) {
                        $( "#result" ).html(response);//html( r );
                        if(response=="led acceso")
                            document.getElementById("event").src="ledon.png";
                        else
                            document.getElementById("event").src="ledoff.png";
                        if (toggled) {
                            $("#jqxButton")[0].value = 'Toggled On';
                        }
                        else $("#jqxButton")[0].value = 'Toggled Off';
                    },
                    error: function() {
                        if(response=="led acceso")
                            $( "#result" ).html("Arduino non è stato in grado di accendere il led");
                        else
                            $( "#result" ).html("Arduino non è stato in grado di spegnere il led");
                    }
                });
            };       
        </script>
    </head>
    <body>
        <center>
            <div>
                <input type="button" onclick="invia('pinD7','led acceso')" value="Toggled On" id='jqxButton' />
            </div>
            <div id="result">  
            </div>
            <img id="event" src="ledoff.png" alt="Accendi" title="Accendi" width="25" height="25"/>
        </center>
    </body>
</html>

AJAX发布成功了吗?如果没有,它将不会在成功中执行任何操作。另外,在使用jqxToggleButton设置之后,立即切换的值是多少?Ajax工作成功。唯一不起作用的就是换按钮。我不知道如何显示toggled的值。你知道吗?控制台。日志切换。console.log是您在JS开发中最好的朋友。打开开发工具并发布它所显示的内容。该值为真,但即使我将if语句更改为if!切换结果相同