网页对Javascript代码无响应 [英] Webpage Unresponsive to Javascript Code

查看:85
本文介绍了网页对Javascript代码无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta  charset="utf-8"/>
    <title>Html Page</title>
    <script src="Content/scripts/jquery-1.8.0.min.js"></script>
    <script src="Content/scripts/jquery-ui-1.8.24.custom.min.js"></script>
    <script type="text/javascript">
'I need help. My webpage won't respond to my Javascript code as shown below and was trying to change the table attributes using Javascript but the changes do not show when I load the page in my browser:
        function changeStyle(myTable) {
            var change = document.getElementById("myTable");

            if (change == true) {
                change.style.borderWidth = "4px";
                change.style.backgroundColor = "blue";
            };changeStyle()
        }
        
    </script>
    <style type="text/css">
        .auto-style1 {
            width: 294px;
        }
    </style>
</head>
<body>
    <div>
        <table id="myTable" style="width: 300px; height: 500px; border: solid 1px black; background-color: Red;">
            <tr>
                <td class="auto-style1">Hello </td>

            </tr>

        </table>
    </div>
</body>
</html>

推荐答案

在此代码中,我根本看不到任何事件处理程序.此外,您包括jQuery库,但从不使用它.如果这是您的全部,绝对不奇怪什么都不会发生.

如果要使用我强烈推荐的典型jQuery方法,则只能处理document.ready并在此事件的处理程序中添加其他处理程序,因此您无需在HTML中添加任何处理程序.在这种情况下,此脚本应位于<body>中,而不应位于<head>元素中:
http://docs.jquery.com/Tutorials:How_jQuery_Works [
In this code, I cannot see any event handler at all. Besides, you include jQuery library, but never use it. If this is all you have, absolutely no wonder that nothing happens.

If you want a typical jQuery approach, which I would strongly recommend, you can handle only document.ready and add other handlers in the handler of this event, so you never need adding any handlers in HTML. In this case, this script should come in <body>, not in <head> element:
http://docs.jquery.com/Tutorials:How_jQuery_Works[^].

Also, do you know how to use the debugger?

—SA


这篇关于网页对Javascript代码无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆