Setting a Value of a Textbox in Javascript in the

2019-07-11 08:41发布

问题:

I am trying to set the value of a textbox in a webpage to a certain value by entering this into the url bar:

javascript:document.getElementById("textboxID").value = "Value";

However whenever I do it just returns a blank screen with whatever value I was trying to set written in the corner.

I am using Google Chrome and I know that this problem does not occur on just one website as I have tried it on many, which leads me to believe that the problem is with the browser, not the site.

Does anyone know why this is happening or a way I can set the value of a textbox on a page using javascript in the URL bar?

Thanks, -p0iz0n

回答1:

Putting void 0 at the end doesn't clear the content of the webpage.

javascript:document.getElementById("textboxID").value = "Value";void 0

undefined works, but void 0 is more popular



回答2:

Enter it into the console:

  • right click on the page
  • select 'inspect element*
  • in the new panel, select 'console'
  • enter your command and hit return