【发布时间】:2019-01-07 06:39:15
【问题描述】:
在《氮素概论》中有这样一个例子:
body() ->
#panel { style="margin: 50px;", body=[
#h1 { text="My Page" },
#label { text="Enter Your Name:" },
#textbox { },
#button { id=mybutton, text="Submit" }
]}.
然后他们让你添加一个 alert()'s hello 的事件:
body() ->
[
#button { text="Submit", actions=[
#event{type=click, actions=#alert { text="Hello" }
]}
].
所以我想出了这个:
%% -*- mode: nitrogen -*-
%% vim: ts=4 sw=4 et
-module (my_page).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include("records.hrl").
main() -> #template { file="./site/templates/bare.html" }.
title() -> "Hello from my_page.erl!".
body() ->
wf:wire(#event{
type=click,
trigger=mybutton,
actions="alert('hello')"
}),
#panel{ style="margin: 50px;", body=[
#h1{ text = "My Simple App..." },
#label{ id=mylabel, text="Enter your name:"},
#textbox{ id=mytextbox },
#button{ text="Submit", id="mybutton"}
]}.
本指南会向您展示如何 alert() 在文本框中输入的名称,这似乎很自然。我试过了:
body() ->
wf:wire(#event{
type=click,
trigger=mybutton,
actions="alert(obj('mytextbox').text)"
}),
#panel{ style="margin: 50px;", body=[
#h1{ text = "My Simple App..." },
#label{ id=mylabel, text="Enter your name:"},
#textbox{ id=mytextbox },
#button{ text="Submit", id="mybutton"}
]}.
...但是 alert() 说 undefined。我什至找不到obj() 函数的文档。
我也尝试使用纯 js 进行操作,因为the guide says:
什么是氮作用?
一个动作可以是 Javascript,也可以是一些渲染成的记录 Javascript。
body() ->
wf:wire(#event{
type=click,
trigger=mybutton,
actions="alert(document.getElementById('mytextbox').innerHTML)"
}),
#panel{ style="margin: 50px;", body=[
#h1{ text = "My Simple App..." },
#label{ id=mylabel, text="Enter your name:"},
#textbox{ id=mytextbox },
#button{ text="Submit", id="mybutton"}
]}.
但是,没有弹出警报()。有人可以帮忙吗?
编辑: 好吧,当我查看页面源时,html看起来像这样:
<input type="text" class="wfid_temp182655 wfid_mytextbox textbox" value="" />
<input type="button" value="Submit" class="wfid_temp182684 wfid_mybutton button" />
我注意到,即使按钮和文本框记录有一个 id 字段,Non 也没有为这些 html 元素设置 id 属性——这对我来说毫无意义。
【问题讨论】: