简体   繁体   English

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

[英]Using Jquery to change field value in webpage using Chrome Extension

I am attempting to change the value of a field on a page with a Google Chrome extension using JQuery 我正在尝试使用JQuery更改带有Google Chrome扩展程序的页面上字段的值

My Code are as follows, 我的代码如下,

manifest.json 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"
  }
}

popup.html popup.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>

and lastly popup.js 最后是popup.js

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

}));

My issue is when the link Watch is clicked its suppose to fill in the web page form with ID name with the word "Hello" but nothing seems to work. 我的问题是,单击链接“监视”时,它应该以ID名称和单词“ Hello”填写Web表单,但似乎无济于事。

Any help would be greatly appreciated! 任何帮助将不胜感激! Thank you for reading. 感谢您的阅读。

This is probably because you popup.html does not have element with id "name". 这可能是因为您popup.html没有ID为“ name”的元素。 Or do you use different html in your extension? 还是在扩展程序中使用其他html?

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

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