1

我正在开发一个 chrome 扩展程序,它会检查在后台选项卡中打开了哪个网站,然后它会解析它。但我不知道为什么表单中的提交按钮不起作用,即使它在我开发的一种类似的扩展中工作。

这是HTML代码

<html>
<head>
    <script src="fetcher.js"></script>
</head>
<body style="min-width:250px; ">
    <form name="login" action="http://localhost/CD/worker.php"  style="padding:15%" method="GET">
    <fieldset>
        <legend>CD</legend>
        <div id="tag"></div>
        <p>
            <label for="name"></label>
            <br />
            <input type="hidden" id="name" name="val" class="text" size="20" />
        </p>

        <p>
            <button type="submit" class="button positive">
            <img alt="ok" src=
            "/tick.png" /> 
            Login
            </button>
        </p>
    </fieldset>
    </form>
</body>

这是我的 JavaScript 文件

window.addEventListener("load", windowLoaded, false);
function windowLoaded() {
    chrome.tabs.getSelected(null, function(tab) {
        //doing stuff with the url
        var url=tab.url;

        if(url.indexOf(".com")>0)
            var n=url.split(".com");
        else if(url.indexOf(".co.in")>0)
            var n=url.split(".co.in");
        else
            var n=url.split(".in");

        var m=n[0].split(".");
        n=m[m.length-1].split("://");
        var qstr=n[0];

        document.getElementById("tag").innerHTML="Get Coupons for "+qstr;
        document.getElementsByName("val").value=""+qstr;    
    });
}

PHP 文件

<?php
    $name=$_GET['val'];
    echo $name;
?>
4

1 回答 1

2

我能够让我的提交按钮使用以下内容:

document.querySelector("form").addEventListener("submit", function(event) {
  event.preventDefault();
  //do stuff
});
于 2014-10-14T04:03:21.600 回答