HTML 文件
<div id="demo">
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<button data-bind="click: myFunctionSave">Save</button>
<button data-bind="click: myFunctionCancel">Cancel</button>
</div>
<script type='text/javascript' src='ViewModel/knockout-2.3.0.js'></script>
<script type='text/javascript' src='ViewModel/main.js'></script>
JavaScript 文件
function myFunctionSave() {
this.firstName = "save";this.lastName = "saveSurname";
}
function myFunctionCancel() {
this.firstName = "cancel";this.lastName = "cancelSurname";
}
ko.applyBindings(new myFunctionSave());
ko.applyBindings(new myFunctionCancel());
.htaccess
我无法在 ubuntu 12.04 lts 中创建 .htaccess。我已经取消隐藏它,甚至在 Apache 中完成了所有操作,但它仍然重定向到本地主机主页并显示“是的,它正在工作”,但没有重定向到 index.html。
试过这段代码它正在工作的html文件
<div class='demo'>
<button data-bind='click: save'>save</button>
<button data-bind='click: cancel'>cancel</button>
</div>
<script type='text/javascript' src='ViewModel/knockout-2.3.0.js'></script>
<script type='text/javascript' src='ViewModel/main.js'></script>
文件
var student = function() {
var self = this;
self.save = function() { alert("save" ); };
self.cancel = function() { alert("cancel" ); };
};
ko.applyBindings(new student());
但为什么这段代码不能正常工作 html 文件
<div class='demo'>
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<button data-bind='click: save'>save</button>
<button data-bind='click: cancel'>cancel</button>
</div>
<script type='text/javascript' src='ViewModel/knockout-2.3.0.js'></script>
<script type='text/javascript' src='ViewModel/main.js'></script>
脚本文件
var student = function() {
var self = this;
self.save = function() { alert("save" );
self.firstName="save";
self.lastName="saveLastname"; };
self.cancel = function() { alert("cancel" );
self.firstName="cancel";
self.lastName="cancelLastname"; };
};
ko.applyBindings(新学生());
请帮忙