Ach*_*ian 5 frontend functional-programming elm reactive
我正在尝试type为输入设置属性:
input [ type "checkbox" ] []
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
Run Code Online (Sandbox Code Playgroud)It looks like the keyword `type` is being used as a variable. input [ type "checkbox" ] [] ^ Rename it to something else.
当我尝试使用时
input [ type' "checkbox" ] []
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Run Code Online (Sandbox Code Playgroud)Ran into a single quote in a variable name. This was removed in 0.18! input [ type' "checkbox" ] [] ^ Change it to a number or an underscore, like type_ or type1 Or better yet, choose a more descriptive name!
如果我试试
input [ type_ "checkbox" ] []
Run Code Online (Sandbox Code Playgroud)
我收到另一个错误:
Run Code Online (Sandbox Code Playgroud)Cannot find variable `type_` input [ type_ "checkbox" ] [] ^^^^^
那我怎么能最终设置这个属性呢?
Cha*_*ert 10
确实命名了正确的函数type_并且它位于Html.Attributes模块中.确保您正确导入它.
-- this exposed type_, checked, and value (as examples)
import Html.Attributes exposing (type_, checked, value)
-- alternatively, to expose everything,
import Html.Attributes exposing (..)
Run Code Online (Sandbox Code Playgroud)
看起来您在elm文件中缺少import语句,您可以通过导入该属性
import Html.Attributes exposing (type_)
Run Code Online (Sandbox Code Playgroud)
或者,只需导入所有内容,就像这样
import Html.Attributes exposing (..)
Run Code Online (Sandbox Code Playgroud)
那么你发布的例子就可以了.
input [ type_ "checkbox" ] []
Run Code Online (Sandbox Code Playgroud)
当我在elm中编写html并且需要查找某些东西时,我喜欢做的是使用此站点,在右上角我可以搜索我正在寻找的东西.甚至完整的例子!:)
快乐的Elming!