javascript - 包括 js 和 css 不工作

标签 javascript html css

我正在试用这个简单的 css 和 js 密码强度检查器。当 css 和 js 包含在如下文件中时,它工作得很好。但是,如果我将 js 放在一个单独的文件中并将其包含在此文件中,它将不起作用。此外,如果我将 css 放在外部 css 文件中,它不会设置页面样式。

为了包含它,我只是把:

<link rel="stylesheet" type="text/css" href="/css/style.css" />
<script type="text/javascript" src="/js/js.js"></script>

我没有看到我做错了什么,或者它与代码有关并且出于某种原因需要在同一个文件中?

该文件是一个 php 文件,因为我稍后会向其中添加 php 但这不会改变任何东西吗?

<html>
<head>
    <title>strength check</title>
    <style type="text/css">
    #passwordStrength {
        height:10px;
        display:block;
        float:left; 
    }
    .strength0 {
        width:150px;
        background:#cccccc;
    }     
    .strength1 {
        width:20px;
        background:#ff0000;
    } 
    .strength2 {
        width:40px;    
        background:#ff5f5f;
    } 
    .strength3 { 
        width:60px;
        background:#56e500;
    }
    .strength4 {
        background:#4dcd00;
        width:80px;
    } 
    .strength5 { 
        background:#399800;
        width:150px;
    } 
    </style>
    <script language="javascript" type="text/javascript">
    function passwordStrength(password) {

        var desc = new Array();
        desc[0] = "Very Weak";
        desc[1] = "Weak";
        desc[2] = "Better";
        desc[3] = "Medium";
        desc[4] = "Strong";
        desc[5] = "Strongest";

        var score = 0;

        //if password bigger than 6 give 1 point
        if (password.length > 6) score++;

        //if password has both lower and uppercase characters give 1 point      
        if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))) score++;

        //if password has at least one number give 1 point
        if (password.match(/\d+/)) score++;

        //if password has at least one special caracther give 1 point
        if (password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)) score++;
        //if password bigger than 12 give another 1 point
        if (password.length > 12) score++;

        document.getElementById("passwordDescription").innerHTML = desc[score];
        document.getElementById("passwordStrength").className = "strength" + score;
    }​
    </script>   
</head>
<body>
    <input type="password" caption="password" name="password" onkeyup="passwordStrength(this.value);" size="60">
    <div style="font-size: 10px"; id="passwordDescription">Password Strength</div>
    <div class="strength0" id="passwordStrength"></div> 
</body>
</html>

最佳答案

删除链接开头的 / :

<link rel="stylesheet" type="text/css" href="css/style.css" />
<script type="text/javascript" src="js/js.js"></script>

/ 表示您的文件位于域的根目录中。

关于javascript - 包括 js 和 css 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11344610/

相关文章:

javascript - SVG Camera Pan - Translate 每次都重置为 0?

html - 相当于 <big> 的 CSS

javascript - 用零初始化javascript数组

javascript - 在 Ruby on Rails 中通过 Test::Unit 和 Capybara 使用 Javascript 进行集成测试

javascript - 销毁一个元素会破坏该元素上的绑定(bind)?

html - 使用 CSS 我怎样才能使滚动条出现以访问在窗口调整大小时消失的 div?

javascript - 根据屏幕尺寸折叠 div 元素

javascript - 将两个按钮元素合并为一个

html - 如何在 TBody 中将 TH Header 与 TD 对齐

javascript - 我如何将侧边栏包装器移动到单杠下方