我正在尝试使用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"
}
}
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");
})
}));
我的问题是,当点击链接Watch时,它想要填写带有ID名称和“Hello”字样的网页表单,但似乎没有任何效果。
任何帮助将不胜感激!谢谢你的阅读。
答案 0 :(得分:0)
这可能是因为你的popup.html没有id为“name”的元素。或者您在扩展程序中使用不同的HTML?