简体   繁体   English

如何使用书签更改HTML元素的值

[英]How to change the value of a HTML Element using a bookmarklet

I'm not very familiar with JS and I was wondering how I could edit an element of a website using a bookmarklet 我对JS不太熟悉,我想知道如何使用小书签编辑网站的元素

I was trying to change the value of 58 in the following code: 我试图在以下代码中更改58的值:

<span class="rbx-text-navbar-right" id="nav-robux-amount">58</span>

Yet I had no luck, as I had used different information from different sites. 但是我没有运气,因为我使用了来自不同站点的不同信息。

Could someone please help me? 有人可以帮我吗? If I'm not being specific enough, please tell me. 如果我不够具体,请告诉我。

Set the URL of the bookmarklet to: 将书签的URL设置为:

javascript: (code) javascript:代码)

in order to run JavaScript in a bookmarklet. 为了在小书签中运行JavaScript。 In your case, you would want 就您而言,您想要

javascript:document.getElementById("nav-robux-amount").innerHTML="59";

Replace 59 with your value. 用您的值替换59。 Then, whenever you click the bookmark the script should activate. 然后,无论何时单击书签,脚本都应激活。

Break-down 分解

  1. javascript: indicates that we are executing a script. javascript:表示我们正在执行脚本。
  2. document.getElementById("nav-robux-amount") selects the correct element to modify. document.getElementById("nav-robux-amount")选择要修改的正确元素。
  3. .innerHTML refers to the HTML code that is inside the element. .innerHTML是指元素内的HTML代码。
  4. ="59"; completes the statement by changing .innerHTML to 59. 通过将.innerHTML更改为59来完成语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM