更新代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script src="http://github.com/downloads/SteveSanderson/knockout/knockout-2.2.0.js" type="text/javascript"></script>
</head>
<body>
<form id="new-pub">
<input data-bind="value: Title" /><br/>
<select size="10" multiple="multiple"
data-bind="selectedOptions: Attachment, options: AttachmentSelect"></select>
</form>
<script type="text/javascript">
var AttachmentSelect=["C2012_info_mail.pdf", "C2012_programme.pdf"];
var viewModel =
{
Title : ko.observable('Hello world'),
Attachment: ko.observableArray([ "C2012_info_mail.pdf" , "C2012_programme.pdf" ])
};
ko.applyBindings(viewModel, document.getElementById("new-pub"));
</script>
</body>
</html>
预期,该selected
项目被突出显示(选择),但没有任何反应。为什么?