0

JQuery を使用して、Google Chrome 拡張機能を使用してページのフィールドの値を変更しようとしています。

私のコードは次のとおりです。

マニフェスト.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

<!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>

そして最後に popup.js

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

}));

私の問題は、ウォッチのリンクがクリックされたときに、Web ページのフォームに「Hello」という単語の ID 名を入力することを想定していますが、何も機能していないようです。

どんな助けでも大歓迎です!読んでくれてありがとう。

4

1 に答える 1

0

これはおそらく、popup.html に ID「name」の要素がないためです。または、拡張機能で別の html を使用していますか?

于 2013-09-13T13:16:43.203 に答える