将 ENTER 键重新定义为 TAB 键
Redefining the ENTER key into a TAB key
如何使 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
一起包含在 shiny 中。
如何使 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
一起包含在 shiny 中。