简体   繁体   English

如何在 pdfjs 中添加 onclick()

[英]How to add onclick() in pdfjs

I'm trying to add a onclick() event in pdfjs.我正在尝试在 pdfjs 中添加一个 onclick() 事件。

I have tried adding a method to handle the onclick in pdf.js file.我尝试在 pdf.js 文件中添加一种方法来处理 onclick。 I'm getting this error on click "Uncaught ReferenceError: displayAttachmentsOnLocation is not defined".单击“未捕获的 ReferenceError:未定义 displayAttachmentsOnLocation”时出现此错误。

In Html:在 Html 中:

<div class="page-margin" onclick="displayAttachmentsOnLocation(1)">

In Pdf.js:在 Pdf.js 中:

function displayAttachmentsOnLocation(locationId) {
   var panel = parent.angular.element(parent.document.getElementById('attachments-panel')).scope().vm;
   panel.displayAttachmentsOnLocation(locationId);
 }

I want to call the displayAttachmentsOnLocation() onclick event on pdf我想在 pdf 上调用 displayAttachmentsOnLocation() onclick 事件

It's better to use the ng-click="" directives like that:最好像这样使用ng-click=""指令:

<div class="page-margin" ng-click="$ctrl.displayAttachmentsOnLocation(1)"></div>

Another think, you haven't specified the name of the controller when you call the method.另一种想法是,您在调用该方法时没有指定 controller 的名称。

Controller: Controller:

  angular.module('app', ['$scope']).controller('repeatController', function($scope) {

  $scope.displayAttachmentsOnLocation = (locationId) => {
      // Write here the logic
  };
});

If you want to add onclick event on pdfjs:如果要在 pdfjs 上添加 onclick 事件:

var element = document.getElementById('idElement');
element.addEventListener('click, (event) => {
   // Do some logic here when click event is fired
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM