how to enter a random value in a textarea without an id?

前端 未结 3 1943
花落未央
花落未央 2021-01-24 17:33

I have to enter a random value in a textarea of a web site by using grease monkey script the text area didn\'t have an id so document.getElementB

3条回答
  •  甜味超标
    2021-01-24 18:01

    It might be helpful to use getElementsByTagName:

    document.getElementsByTagName("textarea")[0]
    

    Of course, if you have more than one textarea tag, you will have to distinguish between them based on properties they might have. Or, if you know your textarea resides inside a specific element which has an ID, you could try

    document.getElementById("someparentid").getElementsByTagName("textarea")[0]
    

提交回复
热议问题