Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在内容脚本chrome扩展中使用jquery_Javascript_Jquery_Google Chrome Extension - Fatal编程技术网

Javascript 如何在内容脚本chrome扩展中使用jquery

Javascript 如何在内容脚本chrome扩展中使用jquery,javascript,jquery,google-chrome-extension,Javascript,Jquery,Google Chrome Extension,如何在content.js中使用Jquery 这是我的密码 manifest.json "background": { "scripts": ["jquery-1.12.2.min.js","background.js"] }, "content_scripts": [{ "matches": [ "http://*/*", "https://*/*"], "js": ["jquery-1.12.2.min.js","content.js"] }],

如何在content.js中使用Jquery

这是我的密码

manifest.json

    "background": {
    "scripts": ["jquery-1.12.2.min.js","background.js"]
  },
  "content_scripts": [{
    "matches": [ "http://*/*", "https://*/*"],
    "js": ["jquery-1.12.2.min.js","content.js"]
  }],
    "permissions": [
    "tabs",
    "activeTab",
    "http://*/*",
    "https://*/*",
    "<all_urls>"

  ]
content.js

chrome.tabs.create({url: "https://www.google.com/search?gws_rd=cr&as_qdr=all&q=" + encodeURIComponent(searchQ)}, function (tab){openSearchLink(tab)});
var createdTabId = 0;
function openSearchLink(tab){
    console.log("new tab "+tab.id);
    createdTabId = tab.id;

}
// Listen for messages
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
    // If the received message has the expected format...
    if (msg.text === 'report_back') {
        // Call the specified callback, passing
        // the web-page's DOM content as argument
        var resAry = {};
        console.log('dddd-'+$('#bname').val());
        resAry['bName'] = $('#bname').val().trim();
        sendResponse(resAry);
    }
});

resAry['bname']正在返回空响应。其中,当我使用document.getElementById时,我得到了值。在popup.html中添加下面的行就成功了

<script src="jquery-1.12.2.min.js"></script>


首先,您可以检查前端页面上是否有jQuery文件??我检查你的例子,它显示为空?我没有任何头版/popup.html。我正在尝试从加载的选项卡读取dom内容,行在哪里?