首页 > 解决方案 > SharePoint 的 Web 部件自定义,按钮 Onclick 功能在 typescript 中不起作用

问题描述

SharePoint 的 Web 部件自定义,按钮 Onclick 功能在 typescript 中不起作用。我们使用 NPM 和 typescript 自定义了 Web 部件。在打字稿中,当我们为该按钮分配函数调用时,onclick 事件不起作用。你能提供解决方案吗?

public openNewPage():void  {
let site = this.context.pageContext.site.absoluteUrl;
console.log("Site: "+site);

const webPart: CreatePageWebPart = this;
window.onload= function (){
this.document.querySelector('#btnCopy').addEventListener('click', () => {
  var headtext =  document.getElementById("pageName");
  alert(headtext);
  
  });
}}

标签: javascripttypescriptsharepoint

解决方案


推荐阅读