Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.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
为什么我的javascript代码不起作用?_Javascript_Jquery - Fatal编程技术网

为什么我的javascript代码不起作用?

为什么我的javascript代码不起作用?,javascript,jquery,Javascript,Jquery,我创建了new.html和new.js文件 新的.html代码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery

我创建了new.html和new.js文件

新的.html代码:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script type="text/javascript" src="new.js"></script>
        <title>Untitled Document</title>
        <style>
            table {
                border-collapse: collapse;
                width: 100%;
            }
            td {
                border: 1px solid black;
            }
        </style>
    </head>
    <body>
        <table>
            <tr>
                <td><span id="first">6</span></td>
                <td>
                    <select id="seconde">
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                    </select>
                </td>
                <td><span id="third">X</span></td>
            </tr>
        </table>
    </body>
</html>
当我选择一个数字时,X没有改变


例如,当我在“选择”部分中选择5时,我希望将数字30替换为X。但X不会改变。我该怎么做呢?

您的事件绑定似乎是错误的。。。您需要绑定到select上的更改事件

我想这就是你想要的:

$'seconde'.changefunction{ var first=document.getElementById'first'。innerHTML; var seconde=document.getElementById'seconde'。值; var third=parseIntfirst*parseIntseconde; document.getElementById'third'。innerHTML=third; }; 6. 1. 2. 3. 4. 5. X $'seconde'。关于'change',函数{ var first=document.getElementById'first'。innerHTML; var seconde=document.getElementById'seconde'。值; var third=parseIntfirst*parseIntseconde; document.getElementById'third'。innerHTML=third; };
无标题文档表{border collapse:collapse;width:100%;}td{border:1px纯黑;}6 1 2 3 4 5 X您必须添加更改处理程序,因为在select下拉列表中您没有键入任何内容,没有意义在keyup事件中添加处理程序

$document.readyfunction{ $document.changefunction{ var first=document.getElementById'first'。innerHTML; var seconde=document.getElementById'seconde'。值; var third=parseIntfirst*parseIntseconde; document.getElementById'third'。innerHTML=third; }; }; 无标题文件 桌子{ 边界塌陷:塌陷; 宽度:100%; } 运输署{ 边框:1px纯黑; } 6. 1. 2. 3. 4. 5. X
但是绑定到全局更改处理程序似乎仍然不是一个好主意,因为当您在带有更改事件的页面上添加更多输入等时,它们将触发此事件。
$(document).keyup(function () {
    $(document).change(function () {
        var first= document.getElementById('first').innerHTML;
        var seconde= document.getElementById('seconde').value;
        var third= parseInt(first) * parseInt(seconde);
        document.getElementById('third').innerHTML = third;
    });
});