我希望在Websharper中获得用户在整个页面中的键盘输入(或任何最接近我的内容),但我看不到任何好的方法来做到这一点。
我尝试过一些类似的东西
JQuery.Of("document").Keyup(fun _ _ -> Window.Self.Alert("boo"))但是我总是碰到很多NotImplementedExceptions。这些真的没有实施吗?或者,我遇到了一些奇怪的边缘案例,因为我违背了规则?
更新:
我已经从nuget安装了2.4.85.235版本,如果这对任何人有任何意义的话。我也在使用VS 2012。
我还测试了VS2010中的一个全新的sitelets模板化站点,我看到了同样的东西。我已经从WebSharper站点安装了最新的包。
发布于 2012-10-28 17:58:27
确保您调用的客户端方法不是在服务器上实现的。如果是这种情况,则将客户端和服务器代码分开,显示涉及的元素并通过Web Control机制调用JavaScript,并使用"html“、"body”或Dom.Document.Current作为选择器。以下是每次按enter键时显示警报的示例:
module Client =
open IntelliFactory.WebSharper
open IntelliFactory.WebSharper.Html
open IntelliFactory.WebSharper.JQuery
[<JavaScriptAttribute>]
let paragraph () =
P [Text "Press the Enter key to display an alert box."]
|>! OnAfterRender (fun x ->
JQuery.Of("html").Keydown(fun _ event ->
match event.Which with
| 13 -> JavaScript.Alert "Enter key was pressed."
| _ -> ()).Ignore)
type ParagraphViewer () =
inherit Web.Control()
[<JavaScript>]
override this.Body = paragraph () :> _https://stackoverflow.com/questions/13107181
复制相似问题