如何检测Racket网络应用程序上的按键

如何检测Racket网络应用程序上的按键

本文介绍了如何检测Racket网络应用程序上的按键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我的基本Web应用程序的代码:

>

  #lang racket 

(需要web-server / servlet
web-server / servlet-env )

(define test())

(define(start request)
(define bindings(request-bindings request))
(cond
((exists-binding?`cb1 bindings)
(set!test'(1 2 3))
(printf〜a(test)has been set to'(1 (b)(
(head(title)My Blog))
(body
(h1正在建设中)
(form,`(input((namecb1)(typecheckbox))(valueCheckbox 1))
(p(input((typesubmit )(valueSubmit)))))))))

(serve / servlet start)

我希望能够提交而无需按提交,而是按下输入等键。是否有可能做到这一点?

解决方案

Racket servlet生成发送给客户端的网页(以html格式)。
在客户端,网页显示在用户的浏览器中。当用户按下一个键时,浏览器需要处理它。让浏览器在按键上执行任何特殊操作的唯一方法是在JavaScript中使用写入处理程序。请注意,程序的Racket部分只能在服务器上运行。

简单地说:您需要编写一小段JavaScript并将其嵌入html页面。



请参阅
了解如何在JavaScript中执行此操作的更多信息。


I've been through the documentation for web-servers and can't find anything on it.

Here's my code for a basic web application:

#lang racket

(require web-server/servlet
         web-server/servlet-env)

(define test '())

(define (start request)
  (define bindings (request-bindings request))
  (cond
    ((exists-binding? `cb1 bindings)
     (set! test '(1 2 3))
     (printf "~a" "(test) has been set to '(1 2 3)!")))
  (response/xexpr
   `(html
     (head (title "My Blog"))
     (body
      (h1 "Under construction")
      (form ,`(input ((name "cb1") (type "checkbox")) (value " Checkbox 1"))
            (p (input ((type "submit") (value "Submit")))))))))

(serve/servlet start)

I want to be able to submit without having to press submit and instead by pressing a key such as enter. Is it possible to do this?

解决方案

The Racket servlet produces a web page (in html) that is sent to the client.On the client the web page is shown in the user's browser. When the user press a key the browser needs to handle it. The only way to get the browser to do anything special on a key press is to use write a handler in JavaScript. Note that the Racket portion of your program only runs on the server.

In short: You need to write a small piece of JavaScript and embed it in the html page.

See How to submit form on keypress?for more information on how to do this in JavaScript.

这篇关于如何检测Racket网络应用程序上的按键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 03:56