我是淘汰 js 的新手,需要帮助。我想,当我在文本框中添加数字时,应该调整到像素的大小。
以下是代码:
<html>
<head>
<style type="text/css">
#myDiv {
border:solid 1px #f00;
}
#myOtherDiv {
border:solid 1px #00f;
width: 150px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.1.0/knockout-min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var viewModel = {
myWidth: ko.observable( '250px'),
anotherDiv: ko.observable('KO is working')
};
ko.applyBindings(viewModel);
});
</script>
</head>
<body>
<div id="myDiv" data-bind="style: { width: myWidth }">
Some Text
</div>
<div id="myOtherDiv">
Some More Text
</div>
<div data-bind="text: anotherDiv"></div>
Enter size<input type = text />
</body>
</html>