【发布时间】:2017-09-18 14:34:45
【问题描述】:
如何使 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 中。
【讨论】: