react子组件不响应click事件

时间:2015-12-07 19:26:41

标签: javascript html reactjs

我遇到的问题是该组件没有在按钮 点击 上触发点击事件。

TickerPage

render() {
  return (
    <div className="TickerPage">
      <div className="TickerPage-container">
        <br />

        <div className='leftContainer'>
          <PlayersTable players={this.state.players} />
        </div>

        <div className='rightContainer'>
          <PlayerDetail playerid={this.state.playerid} />
        </div>

        <div className='bottomTicker'>
          <Ticker />
        </div>
      </div>
    </div>
  );

PlayersTable

render() {
  let tbl = this.buildTable();

  return (
    <div className="PlayersTable">
      <div className="PlayersTable-container">

        <button onclick='alert("test")'>test</button>

        <h1 className='heading'>Players</h1>
        {tbl}
        <br />
      </div>
    </div>
  );
}

当我点击PlayersTable上的按钮时,没有任何反应。它应该有一个警告框。

谢谢!

2 个答案:

答案 0 :(得分:1)

它在你的情况下不起作用的原因应该是一个函数参考。

分配点击事件的最佳方法是在#define TRANSFER_LENGTH_FROM_HOST (128) //Burst input #define TRANSFER_LENGTH_FROM_FPGA (128) // Burst output #define NUM_TRANSFERS (50) #include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "ZestSC2.h" void ErrorHandler(const char *Function, ZESTSC2_HANDLE Handle, ZESTSC2_STATUS Status, const char *Msg) { printf("**** Example2 - Function %s returned an error\n \"%s\"\n\n", Function, Msg); exit(1); } int main(int argc, char **argv) { unsigned long Count; unsigned long NumCards; unsigned long CardIDs[256]; unsigned long SerialNumbers[256]; ZESTSC2_FPGA_TYPE FPGATypes[256]; ZESTSC2_HANDLE Handle; unsigned __int64 Freq; unsigned __int64 Start; unsigned __int64 End; unsigned long *Buffer_tx; unsigned long *Buffer_rx; FILE *fp; errno_t err = fopen_s(&fp, "C:/Users/Shankhadeep/Documents/results.csv", "w+"); // Install an error handler ZestSC2RegisterErrorHandler(ErrorHandler); // Request information about the system ZestSC2CountCards(&NumCards, CardIDs, SerialNumbers, FPGATypes); printf("%d available cards in the system\n\n\n", NumCards); if (NumCards==0) { printf("No cards in the system\n"); exit(1); } for (Count=0; Count<NumCards; Count++) printf("%d : CardID = 0x%08lx, SerialNum = 0x%08lx, FPGAType = %d \n \n", Count, CardIDs[Count], SerialNumbers[Count], FPGATypes[Count]); // Open the first card ZestSC2OpenCard(CardIDs[0], &Handle); printf("Reading the bit file .. \n"); if (FPGATypes[0] == ZESTSC2_XC3S2000) ZestSC2ConfigureFromFile(Handle, "C:/Users/Shankhadeep/Documents/Example2_4000.bit"); else ZestSC2ConfigureFromFile(Handle, "C:/Users/Shankhadeep/Documents/example2.bit"); // Send data to the card - Generate a 64-bit random number in Buffer Buffer_tx = malloc(TRANSFER_LENGTH_FROM_HOST); Buffer_rx = malloc(TRANSFER_LENGTH_FROM_FPGA); for (Count = 1; Count < TRANSFER_LENGTH_FROM_HOST / 2; Count++) { ((unsigned long *)Buffer_tx)[Count] = (unsigned long)(1 << (Count - 1)); printf("Writing %x \n", Buffer_tx[Count]); } QueryPerformanceFrequency((LARGE_INTEGER *)&Freq); QueryPerformanceCounter((LARGE_INTEGER *)&Start); for (Count=0; Count<NUM_TRANSFERS; Count++) { ZestSC2WriteData(Handle, Buffer_tx, TRANSFER_LENGTH_FROM_HOST); for (Count = 0;Count<TRANSFER_LENGTH_FROM_HOST / 2; Count++) //fwrite(Buffer_tx, 64, 128, fp); //Throws an error as soon as I write this line fprintf(fp, "%s", Buffer_tx[Count]); } QueryPerformanceCounter((LARGE_INTEGER *)&End); printf("Transfer rate to card = %.2fMBytes/sec\n", ((double)NUM_TRANSFERS*(double)TRANSFER_LENGTH_FROM_HOST*(double)Freq)/(1024.*1024.*(double)(End-Start))); // Read data from the card QueryPerformanceCounter((LARGE_INTEGER *)&Start); // for (Count=0; Count<NUM_TRANSFERS; Count++) // { ZestSC2ReadData(Handle, Buffer_rx, TRANSFER_LENGTH_FROM_FPGA); for (Count = 0; Count < 64; Count++) { printf("Reading %x \n", Buffer_rx[Count]); } // } QueryPerformanceCounter((LARGE_INTEGER *)&End); printf("\n"); printf("Transfer rate from card = %.2fMBytes/sec\n", ((double)NUM_TRANSFERS*(double)TRANSFER_LENGTH_FROM_FPGA*(double)Freq)/(1024.*1024.*(double)(End-Start))); printf("End : %d Start: %d \n", End, Start); if (!fp)perror("fopen_s"); printf("Error is %d", err); if (err != NULL) fprintf(fp, "Hello"); else printf("Exit \n"); ZestSC2CloseCard(Handle); return 0; } 方法中执行此操作。

<强> JS

Debug Assertion Failed!
Program .. fpga_2_host.exe 
File minkernel\crts\ucrt\src\appcrt\stdio\output.cpp Line 31
Expression: stream != nullptr

我个人会避免在内联HTML中包含函数定义。

答案 1 :(得分:0)

问题是我有onclick而不是onClick

谢谢!