我使用contentEditable div,我想在用户修改它之后访问它的内容(onBlur).如何访问DOM元素的innerHtml或textContent?任何的想法 ?
这是一个简单的例子:
import Html exposing (div, text)
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onBlur)
import Html.Attributes exposing (contenteditable)
main =
beginnerProgram { model = "Hello", view = view, update = update }
view model =
div [contenteditable True, onBlur (SaveInput)] [ text model ]
type Msg = SaveInput
update msg model =
case msg of
SaveInput ->
"ok"
Run Code Online (Sandbox Code Playgroud)
我希望使用textContent将公式替换为"ok" 以获取用户输入的值.我正在使用elm v 0.17.
我或python是否与以下代码混淆?我希望__le__被召唤a <= ab,而不是__ge__:
#!/usr/bin/env python2
class B(object):
def __ge__(self, other):
print("__ge__ unexpectedly called")
class A(object):
def __le__(self, other):
print("__le__ called")
class AB(A, B):
pass
a = A()
ab = AB()
a <= ab # --> __ge__ unexpectedly called
ab <= a # --> __le__ called
Run Code Online (Sandbox Code Playgroud)
我得到了与python 2.7,3.2和pypy 1.9相同的行为.
我该怎么办才能被__le__召唤而不是__ge__?
我编译了" Hello world "程序
import Html exposing (text)
main =
text "Hello, World!"
Run Code Online (Sandbox Code Playgroud)
在Windows上使用elm 0.17,没有编译错误:
elm make hello.elm --output index.html
Run Code Online (Sandbox Code Playgroud)
当我在index.html上打开Chrome时,我会看到一个空白页面.Chrome的控制台在index.html中显示2个错误:
Uncaught ReferenceError: _elm_lang$virtual_dom$VirtualDom$text is not defined
Uncaught ReferenceError: Elm is not defined
Run Code Online (Sandbox Code Playgroud)
如果我在该文件上运行elm-reactor,我也会得到一个白页,并在控制台中出现类似的错误.
不知何故,路径丢失了...这是elm-package.json文件:
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.0 <= v < 5.0.0",
"elm-lang/html": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
} …Run Code Online (Sandbox Code Playgroud) 我已将todomvc 示例onenter中的代码改编为 create ,但它不起作用。显然,没有传递给 Elm。那么,我怎样才能检测到shift-Enter呢?onShiftEntershiftKey
onShiftEnter : Msg -> Attribute Msg
onShiftEnter msg =
let
tagger (code, shift) =
if code == 13 && shift then msg else NoOp
in
on "keydown"
(Json.Decode.map tagger
( Json.Decode.tuple2 (,)
(Json.Decode.at ["keyCode"] Json.Decode.int)
(Json.Decode.at ["shiftKey"] Json.Decode.bool)
)
)
Run Code Online (Sandbox Code Playgroud) 我对此非常陌生,我正在尝试创建一个基于文本的扫雷.我希望玩家决定他希望网格有多大.我的问题是,应该确保用户输入1到10之间的数字的if语句不起作用.请看一看.
scanf ("%i/%i",&x,&y);
if (0 < x < 11 && 0 < y < 11)
{
printf ("you have selected %i by %i\n",x,y);
for (i = 0; i < x; i++)
{
for (j = 0; j < y; j++)
{
grid[x][y] = 'O';
printf ("%c ", grid[x][y]);
}
printf ("\n");
}
}
else
printf ("Wrong gridsize");
Run Code Online (Sandbox Code Playgroud)