// 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(); } } };个
1条答案
按热度按时间v2g6jxz61#
假设您的按钮像这样环绕div
HTML程式码:
<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(); } } };
个