第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Mousetrap.js 聚焦輸入字段 - 但輸入字段也將熱鍵粘貼為值?

使用 Mousetrap.js 聚焦輸入字段 - 但輸入字段也將熱鍵粘貼為值?

回首憶惘然 2021-11-12 14:19:26
看看下面的例子。我用一些捕鼠器功能增強(qiáng)了這里的官方示例。因此,每當(dāng)有人按下 時alt+1,第一個輸入字段將聚焦,每當(dāng)有人按下alt+2第二個輸入字段時,將聚焦。有用。問題: 但是,輸入字段也將按下的任何值作為熱鍵(alt+1然后呈現(xiàn)為?,在輸入中alt+2呈現(xiàn)為€)。但我只是希望這是一個熱鍵,我不希望它是輸入字段中的實際值。我該怎么做呢?我可以完全清除/刪除輸入字段。這可以在這里的示例中工作,但我不想這樣做,因為在我的最終應(yīng)用程序中,需要保留輸入字段的狀態(tài),所以我不能只是刪除它。有什么建議嗎?import React from "react"import Mousetrap from "mousetrap"export default class CustomTextInput extends React.Component {  constructor(props) {    super(props)    // create a ref to store the textInput DOM element    this.textInput = React.createRef()    this.textInput2 = React.createRef()    this.focusTextInput = this.focusTextInput.bind(this)  }  componentDidMount() {    Mousetrap.bind("alt+1", () => {      this.focusTextInput(1)    })    Mousetrap.bind("alt+2", () => {      this.focusTextInput(2)    })  }  focusTextInput(id) {    // Explicitly focus the text input using the raw DOM API    // Note: we're accessing "current" to get the DOM node    if (id === 1) {      this.textInput.current.focus()    }    if (id === 2) {      this.textInput2.current.focus()    }  }  render() {    // tell React that we want to associate the <input> ref    // with the `textInput` that we created in the constructor    return (      <div>        <input type="text" ref={this.textInput} className="mousetrap" />        <input type="text" ref={this.textInput2} className="mousetrap" />      </div>    )  }}一世
查看完整描述

1 回答

?
喵喵時光機(jī)

TA貢獻(xiàn)1846條經(jīng)驗 獲得超7個贊

你試過 event.preventDefault() 嗎?


Mousetrap.bind("alt+1", (e) => {

            e.preventDefault();

      this.focusTextInput(1);

    })


    Mousetrap.bind("alt+2", () => {

        e.preventDefault();

    this.focusTextInput(2)

    })


查看完整回答
反對 回復(fù) 2021-11-12
  • 1 回答
  • 0 關(guān)注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號