javascript - 如何使用 javascript 获取用户通过 Google Chrome 上的 html 表单提交的值?

标签 javascript jquery google-chrome google-chrome-extension

我正在编写我的第一个 Chrome 扩展,它具有以下功能。当用户右键单击图像并在上下文菜单中选择适当的字段时,将创建一个包含表单的弹出窗口。从上下文菜单中调用以下函数。

   function new_window(){chrome.windows.create({
                                   url: "reddit.html",
                                   type: "popup",
                                   focused: true,
                                   width: 200,
                                   height:140})

“reddit.html”中包含的表单如下:

     <form id="post_on_forum" method="get">
         <input type="text" name="title" placeholder ="title"><br>
         <input type ="text" name="Category"placeholder ="Category" ></br>
         <input type="submit" value="Submit" id="submit">                   
     </form>

我的问题是:如何使用 Javascript 获取用户每次提交内容时输入的变量?我不能使用内联 javascript,因为 chrome 禁止这样做。我创建了一个 submit.js ,它是

$(document).ready(function() {
    $('#Submit').on('click',(function() {
       foo($('#post_on_forum').val());
    }));

    console.log("triggered");
}); 

但它不起作用。当然,我已在 list 文件中包含了所有适当的文件。

最佳答案

看这个例子http://jsfiddle.net/qt3ZB/

jQuery 有特殊的方法 serialize 来获取表单中的所有值。

希望有帮助。

关于javascript - 如何使用 javascript 获取用户通过 Google Chrome 上的 html 表单提交的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17965125/

相关文章:

javascript - 为什么 classList.remove 不起作用,而 jQuery .removeClass 却起作用?

javascript - 如何使用方法创建 jQuery 插件?

javascript - jQuery - 重用代码而不重复它

javascript - 首先执行代码的错误部分

javascript - 仅检测移动设备上的 Chrome

javascript - 在 jquery ui 1.8 中扩展小部件后销毁不起作用

javascript - JS : why is the var not declared when it is declared inside a method of an object and passed as a parameter to the other method of the same object?

javascript - $(input[]).each 仅在 Firefox 中抛出语法错误

javascript - 通过以下 HTML lang 值更改内部 HTML

html - 当视口(viewport)顶部有固定的分隔线时,Chrome滚动太多