簡體   English   中英

有沒有辦法在React Material上觸發onPaste事件 <TableRow> 在Internet Explorer中?

[英]Is there a way to fire onPaste event on React Material <TableRow> in internet explorer?

我正在設計一個數據表,需要提供能夠粘貼從excel復制的數據行的功能。 但是,onPaste事件不會在Internet Explorer中觸發。 我能夠實現這一點,並在chrome中獲取剪貼板數據。

<Table className={classes.table} aria-labelledby="tableTitle">
            <EnhancedTableHead
              numSelected={selected.length}
              order={order}
              orderBy={orderBy}
              onSelectAllClick={this.handleSelectAllClick}
              onRequestSort={this.handleRequestSort}
              rowCount={data.length}
            />
            <TableBody onPaste={event => this.handlePaste(ClipboardEvent)}>
              {stableSort(data, getSorting(order, orderBy))
                .map(n => {
                  const isSelected = this.isSelected(n.id);
                  return (
                    <TableRow
                      hover
                      onClick={event => this.handleClick(event, n.id)}
                      role="checkbox"
                      aria-checked={isSelected}
                      tabIndex={-1}
                      key={n.id}
                      selected={isSelected}
                    >
                      <TableCell padding="checkbox">
                        <Checkbox checked={isSelected} />
                      </TableCell>
                      <TableCell component="th" scope="row" padding="none">
                        {n.udf}
                      </TableCell>
                      <TableCell align="right">{n.ticker}</TableCell>
                      <TableCell align="right">{n.transType}</TableCell>
                      <TableCell align="right">{n.qty}</TableCell>
                      <TableCell align="right">{n.portfolio}</TableCell>
                    </TableRow>
                  );
                })}
              {emptyRows > 0 && (
                <TableRow style={{ height: 49 * emptyRows }}>
                  <TableCell colSpan={6} />
                </TableRow>
              )}
            </TableBody>
          </Table>

如果您查看文檔,則可以發現支持粘貼事件,並且OnPaste事件的兼容性未知。

我使用OnPaste事件進行了測試,發現該事件在Internet Explorer中正常運行。

問題是Internet Explorer不支持剪貼板數據。

因此,您將無法使用它訪問數據。

在此輸入圖像描述

經過測試的代碼:

 <!DOCTYPE html> <html> <body> <input type="text" onpaste="myFunction()" value="Try to paste something in here" size="40"> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = "You pasted text!"; } </script> </body> </html> 

Internet Explorer 11中的輸出:

在此輸入圖像描述

參考文獻:

(1) HTMLElement .onpaste

(2) 元素:粘貼事件

作為替代方案,您可以嘗試參考以下鏈接中的示例,可以幫助您解決問題。

跨瀏覽器JavaScript復制和粘貼

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM