如何在WordPress插件中调用Javascript函数?

时间:2019-05-06 01:24:33

标签: javascript php wordpress

以下是我插件中的代码。我试图通过“ echo'createToken(1,“ Test Title”,“ Test Desc”);';“来调用smart-contract-connector.js文件中的Javascript函数“ createToken”。这是在插件内部调用JS函数的正确方法吗?

Sub Click(Source As Button)
  Dim session As New NotesSession
  Dim workspace As New NotesUIWorkspace
  Dim db As NotesDatabase
  Dim collection As NotesDocumentCollection

  Set db = session.CurrentDatabase
  Set collection = db.UnprocessedDocuments

  Dim ws As New NotesUIWorkspace
  Dim uiview As NotesUIView
  Set uiview = ws.CurrentView

  answer% = Messagebox("Do you want to set batch number?", 4,"Batch Number")
  If answer% = 6 Then

    InputBatchNo = Inputbox("Please insert the Batch Number.  eg : 2014A")

    If Not InputBatchNo="" Then

      For ii = 1 To collection.count
        Set doc = collection.GetNthDocument(ii)

        currbatchno = doc.PBatchNo(0)
    '--------------------------------------
    Gosub SetNewBatchNo
    '---------------------------------------
    doc.PBatchNo =newbatchno

    '------------ set new acceptance form ---------------------------
    If doc.PStatus(0) = "Active" Then
    Set comdoc = New NotesDocument (db)
    comdoc.Form = "EmpPCSpec"

    comdoc.ATagNo = doc.PTagNo(0)
    comdoc.AYear= Left(InputBatchNo,4)
    comdoc.ADept= doc.PDept(0)
    comdoc.AUserName= doc.PUserName(0)
    comdoc.AUserID= doc.PUserID(0)
    comdoc.AUserGroup= doc.PUserGroup(0)
    comdoc.ALocation= doc.PLocation(0)
    comdoc.AStatus= doc.PStatus(0)
    comdoc.ABatchNo=doc.PBatchNo(0)

    comdoc.AProcessor= doc.PProcessor(0)
    comdoc.ASerialNo= doc.PSerialNo(0)
    comdoc.ABrand= doc.PBrand(0)
    comdoc.AModel= doc.PModel(0)
    comdoc.AType= doc.PType(0)
    comdoc.ADisplayUnit= doc.PDisplayUnit(0)
    comdoc.ADisplaySize= doc.PDisplaySize(0)
    comdoc.ADisplayBrand= doc.PDisplayBrand(0)
    comdoc.ARam= doc.PRam(0)
    comdoc.AHDD= doc.PHDD(0)
    comdoc.AIPAddress= doc.PIPAddress(0)
    comdoc.AOperatingSys= doc.POperatingSys(0)
    comdoc.ACalLicense= doc.PCalLicense(0)

    Call comdoc.ComputeWithForm(False,False)
    Call comdoc.save(True,True)

    '----------------------------------------------------------------

    Call doc.ComputeWithForm(False,False)
    Call doc.save(True,True)
      End If
    Next

    Messagebox("Process completed." & Chr(13) & "Press 'F9' to refresh the view.")

  Else
    Messagebox("Please insert Batch Number.")
  End If

End If

Exit Sub

SetNewBatchNo:

    currbatchno1 = Strtoken(currbatchno, "-", 1)

    If InputBatchNo = currbatchno1 Then
        seqno = Strtoken(currbatchno, "-", 2)
        newseqno = Val(seqno) +1
        newseqno1 = Format(newseqno, "0000")

        newbatchno = InputBatchNo + "-" + newseqno1
    Else
        newbatchno = InputBatchNo + "-" + "0001"
    End If

    Return

End Sub

我在WordPress之外测试了代码,并且可以正常工作。但是在WordPress内部,没有任何反应。顺便说一句,我使用register_activation_hook只是看我的代码是否可以在插件中加载并正常运行。

0 个答案:

没有答案