我正在尝试使用'hasFocus'绑定实现简单的演示代码。示例代码可用here它在浏览器(IE)中也正常工作
当我复制相同的代码并将其粘贴到我的MVC应用程序中时,它将停止工作。即使点击按钮后它没有将焦点设置在文本框上。以下是我的代码:
<div>
<div>
<input data-bind="hasFocus: isSelected" />
<button data-bind="click: setIsSelected">Focus programmatically</button>
<span data-bind="visible: isSelected">The textbox has focus</span>
</div>
</div>
@section scripts{
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.7.1.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/knockout-2.1.0.js")"></script>
<script type="text/ecmascript" src="@Url.Content("~/Scripts/jquery-ui-1.8.20.js")"></script>
<script>
$(function () {
var viewModel =
{
isSelected: ko.observable(false),
setIsSelected: function () { this.isSelected(true) }
};
ko.applyBindings(viewModel);
});
</script>
}
有谁知道这里出了什么问题?