让我们假设我们有两个文件style.css和code.js.
我该如何将它们导入我的html页面?哪种方式最好?
定期
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="code.js"></script>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
PHP的方式
<html>
<head>
<style><?php include_once "style.css"; ?></style>
<script><?php include_once "code.js"; ?></script>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
哪一个是最有用的使用方式?
我有这个代码示例:
function s () {
this.func = [];
this.func.addF = function (str) {
this.func.push(str);
}
}
Run Code Online (Sandbox Code Playgroud)
当我创建该对象的实例时:
var a = new s ();
a.func.addF ("hello");
Run Code Online (Sandbox Code Playgroud)
我得到一个错误说:未捕获的TypeError:无法读取未定义的属性'push'.
我可以理解那时this.func尚未定义,但我该怎么做才能使这项工作成功.请帮忙.