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

前端 未结 3 1916
花落未央
花落未央 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:07

    You could use element.querySelector if you want to be able to specifically target an element using a CSS selector, similar to this:

    var textArea = document.querySelector('table tr td.pd5 textarea.msgbox');
    textArea.value = "My Random Text";
    

    The above is working on the following HTML example:

    Message 
    140 characters max.

    DEMO - Using element.querySelector


    Off course, you can now change the CSS selector to anything you like to match your DOM hierarchy. There is lots of flexibility using element.querySelector.

提交回复
热议问题