在我的html页面中,我有五个按钮。 它们排列在一个DIV中,这些按钮位于页面底部。 当我点击其中一个按钮时,页面会向上滚动。 我想避免这种行为。我想在按钮点击时滚动到相同的DIV。
这可能吗?
<input type="button" value="Update Details" data-bind="onClick: {value: ' Update Details '} />
// This is a custom event handler which is raised on button click
ko.bindingHandlers.onClick = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
element.onclick = function (event) {
event.preventDefault();
// The below function contains business logic
UpdateDetails();
}
}
};
答案 0 :(得分:0)
假设你的按钮像这样包裹在div
HTML code:
<div class="container">
<div class="rows"><input type="button" value="Update Details" data-bind="onClick: {value: ' Update Details '} /></div>
<div class="rows"><input type="button" value="Update Details" data-bind="onClick: {value: ' Update Details '} /></div>
</div>
淘汰赛代码:
// This is a custom event handler which is raised on button click
ko.bindingHandlers.onClick = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
element.onclick = function (event) {
event.preventDefault();
//this will place the target div at top of the page
$(event.target)[0].scrollIntoView();
// The below function contains business logic
UpdateDetails();
}
}
};
快乐编码:)