使用 Jquery 通过 Chrome 扩展程序更改网页中的字段值

Using Jquery to change field value in webpage using Chrome Extension

本文关键字:网页 字段 通过 Jquery Chrome 扩展 程序 使用      更新时间:2023-09-26

我正在尝试使用JQuery更改带有Google Chrome扩展名的页面上字段的值

我的代码如下,

manifest.json

{
  "manifest_version": 2,
  "name": "One-click Kittens",
  "description": "This extension demonstrates a browser action with kittens.",
  "version": "1.0",
  "background": { "scripts": ["jquery.js"] },
  "permissions": [
  "tabs",
  "http://*/"
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}

弹出窗口.html

<!doctype html>
<html>
<head>
  <title>Getting Started Extension's Popup</title>
  <style>
  body {
    min-width: 200px;
    overflow-x: hidden;
  }
  </style>
    <!--
      - JavaScript and HTML must be in separate files: see our Content Security
      - Policy documentation[1] for details and explanation.
      -
      - [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
    -->
    <script src="jquery.js"></script>
    <script src="popup.js"></script>
  </head>
  <body>
    <ul>
      <li><a href="#" id="watch_list">Watch</a>
      </li>
      <li id="assets">Assets
      </li>
      <li id="liab">Liabilities
      </li>
    </ul>
  </body>
  </html>

最后弹出窗口.js

$(document).ready($(function(){
  $('#watch_list').click(function(){
    $('#name').val("Hello");
  })
}));

我的问题是,当单击链接Watch时,它应该使用ID名称填写网页表单,并带有"Hello"一词,但似乎没有任何效果。

任何帮助将不胜感激!感谢您的阅读。

这可能是

因为你弹出.html没有id为"name"的元素。还是在扩展中使用不同的 html?