0
如何讓ENTER像TAB一樣工作,即當用戶在輸入字段中按ENTER時,光標跳到下一個字段,就像按TAB鍵時會發生的那樣?將ENTER鍵重新定義爲TAB鍵
如何讓ENTER像TAB一樣工作,即當用戶在輸入字段中按ENTER時,光標跳到下一個字段,就像按TAB鍵時會發生的那樣?將ENTER鍵重新定義爲TAB鍵
參見下面的示例:
library(shiny)
library(shinyjs)
# Define UI for application that draws a histogram
ui <- fluidPage(
useShinyjs(),
sidebarLayout(
sidebarPanel(
textInput("txt1", "Text: "),
textInput("txt2", "Text: ")
),
mainPanel()
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
observe({
runjs("
var inputs = $(':input').keypress(function(e){
if (e.which == 13) {
e.preventDefault();
var nextInput = inputs.get(inputs.index(this) + 1);
if (nextInput) {
nextInput.focus();
}
}
});
")
})
}
# Run the application
shinyApp(ui = ui, server = server)
的JavaScript是從here並且包括在光澤與shinyjs
。