我在尝试编译它的代码时遇到问题,但它使我无法将也许元素与元素
为什么?可能如何工作?如何将其转换为值?为什么这么难理解单子和函子, 为什么没有一个简单的库来让一些新手开始使用purescript? :P
(对于那些听不懂的人,我只是问前三个)
module Main where
import Prelude --(Unit, bind, pure, ($), (<$>))
import Effect (Effect)
import Data.Maybe --(Just,Maybe,fromJust, fromMaybe)
import Data.Foldable (traverse_)
import Effect.Console (log)
import Web.HTML (window)
import Web.HTML.Window (document)
import Web.HTML.HTMLDocument (toNonElementParentNode)
import Web.Event.Event (Event, target)
import Web.HTML.HTMLInputElement (value, fromEventTarget)
import Web.DOM.NonElementParentNode (NonElementParentNode,getElementById)
import Web.DOM.Node (setTextContent)
import Web.DOM.Element (Element,toNode)
import Web.Event.EventTarget (addEventListener)
pname = "#inputName" :: String
bname = "#badgeName" :: String
main :: Effect Unit
main = do
nod1 <- returnNonElementParentNode
--querySelector :: QuerySelector -> ParentNode -> Effect (Maybe Element)
elementTarget <- getElementById pname nod1
--addEventListener :: EventType -> EventListener -> Boolean -> EventTarget
addEventListener "input" updateBadge false elementTarget
updateBadge :: Event -> Unit
updateBadge event = do
nod2 <- returnNonElementParentNode
elementTarget <- getElementById bname nod2
tget <- target event
inml <- fromEventTarget tget
input <- value inml
badge <- toNode (pure elementTarget)
if not(badge == Nothing)
then setTextContent input (toNode badge)
else Nothing
returnNonElementParentNode :: Effect NonElementParentNode
returnNonElementParentNode = do
win <- window
doc <- document win
--let nd = toNonElementParentNode doc
let
nod = toNonElementParentNode doc
pure nod
我只想了解如何从htmlInputElement获取输入值并将其传递给另一个HTMLElement的textContent
如何将也许转换为值以传递给 toNode 函数
答案 0 :(得分:0)