Setting a Value of a Textbox in Javascript in the URL bar of Chrome just writes the value to the screen

痞子三分冷 提交于 2019-12-12 19:11:59

问题


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


来源:https://stackoverflow.com/questions/13729343/setting-a-value-of-a-textbox-in-javascript-in-the-url-bar-of-chrome-just-writes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!