在html中提交关键字并在javascript中使用

在html中提交关键字并在javascript中使用,javascript,html,forms,Javascript,Html,Forms,我想制作一个html,在其中输入关键字 <html> <head> <title>Options</title> </head> <body> <input name="Keyword" type="text"> <input name="Submit" type="submit" value="Submit"> </body>

我想制作一个html,在其中输入关键字

<html>    
  <head>
    <title>Options</title>
  </head>    
  <body>
    <input name="Keyword" type="text">
    <input name="Submit" type="submit" value="Submit">
  </body>    
</html>

这是一个chrome扩展,因此在选项页面上,我想输入一个关键字,提交它,并让它自动将其放入javascript中,您可以使用

shoeName =  $("input[name='Keyword']").val(); // if you can not add id
如果可以添加id,请执行以下操作

$('#inputid").val()
或者,如果您想要表单上的数据,请提交

<form name="myForm" id="testForm" method="POST" action="send.php"> 
<input name="Keyword" type="text">
<input name="Submit" type="submit" value="Submit"
</form>

var shoeName = "";

$("form[name='myForm']").submit(function(){
    shoeName =  $("input[name='Keyword']").val()
 // other processing
});


您可以通过为元素设置ID并使用ID访问元素来实现这一点

HTML:

<html>    
    <head>
        <title>Options</title>
    </head>    
    <body>
        <input id="keyText" name="Keyword" type="text">
        <input name="Submit" type="submit" value="Submit">
    </body>    
</html>
<script>
    var shoeName = document.getElementById("keyText").value;
</script>

选择权
JS:

<html>    
    <head>
        <title>Options</title>
    </head>    
    <body>
        <input id="keyText" name="Keyword" type="text">
        <input name="Submit" type="submit" value="Submit">
    </body>    
</html>
<script>
    var shoeName = document.getElementById("keyText").value;
</script>

var shoeName=document.getElementById(“keyText”).value;
快乐的编码。

试试这个:

var shoeName;

document.addEventListener('DOMContentLoaded', function() {

    document.getElementById('keyword').addEventListener('keyup', function() {
        shoeName = this.value;
    });

});

每次文本被添加到文本框时,
shoeName
都会被更新。

也提供一个id并使用GetElementById()怎么样?像这样为输入文本设置一个id
&可以像这样在js中引用相同的
var shoeName=document.GetElementById(“keyText”).valueOP期望的是纯JS实现,而不是Jquery。我不知道为什么这不起作用。。我想做一个chrome扩展,它有一个选项页面,你可以在其中输入一个关键词:好吧,兄弟,这似乎是一个新问题,因为你已经在上面创建了一个问题,所以我会检查它,同时让我们关闭这个问题,因为它已经达到了目的。您可以通过记录此解决方案作为答案来结束此问题。