How can I Get input value with Prototype?

后端 未结 4 1228
情歌与酒
情歌与酒 2021-01-02 06:31

I have the following input without any form around it:


         


        
4条回答
  •  清歌不尽
    2021-01-02 06:51

    You need to use the $$ function which returns an array. There are a couple of ways to use an enumerable result.

    If you know there will be only one matching element then use this:

    $$('[name="tb_website static"]').first().value
    

    If there are more than one input (which is valid HTML) then this gets an array of values:

    $$('[name="tb_website static"]').map(Form.Element.getValue)
    

    (By mapping through Form.Element.getValue - aliased as $F - it better handles browser differences and non-input elements that don't store their value in a value attribute)

提交回复
热议问题