How can I Get input value with Prototype?

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

I have the following input without any form around it:




        
相关标签:
4条回答
  • 2021-01-02 06:46
    alert($$('[name="td_website static"]')[0].value)
    
    0 讨论(0)
  • 2021-01-02 06:47

    That because $() function is an alias for getElementById(). Which means you need to give and id in your input :)

    <input type="text" value="myValue" id="td_website static" name="td_website static" class="td_inner_input">
    
    0 讨论(0)
  • 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)

    0 讨论(0)
  • 2021-01-02 07:02

    I'm pretty sure that $('tb_website static') will be looking for an element with that ID not that NAME.

    Have another look at the PrototypeJS Documentation.

    0 讨论(0)
提交回复
热议问题