我正在处理chrome扩展,用户将在表单中输入值(扩展表单),然后单击提交按钮,该值应填充到当前浏览器选项卡表单的文本框中。但我无法传递价值
这里是所有细节: 的的manifest.json
{
"name": "My First Extension",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",
"permissions": [
"tabs", "http://*/*"
],
"content_scripts": [
{
"matches": ["*******weburl*********"],
"js": ["jquery.js","content.js"],
"run_at": "document_start"
}
],
"web_accessible_resources": ["inject.js"]
}
popup.html
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body style="width: 400px">
<div>
<div>Search Bookmarks: <input id="search"></div>
<input type="button" name="submit" value="submit" id="submit">
</div>
</body>
</html>
content.js
(function (chrome) {
var js = document.createElement('script');
js.type = 'text/javascript';
js.src = chrome.extension.getURL('inject.js');
// document.getElementsByTagName('head')[0].appendChild(js);
(document.head || document.documentElement).appendChild(js);
}(chrome));
这是我的 inject.js 文件
$(document).ready(function(){
// alert('Here');
$("#submit").click(function(){
document.getElementById('email').value = 'REWRWRE';
});
})
ID电子邮件是我的网址表单的电子邮件地址,但点击后它没有填写值。如果我刚刚在加载时传递了值,则填充该字段,但不是在点击之后。
提前致谢!!