如何在http GET请求中获取变化的值?

时间:2019-02-11 19:03:16

标签: javascript html get

我试图获取html输入元素的值,该值会在按下按钮或键入值时更改值。最初,它的默认值为1。

<input type="text" name="list_quantity" value="1" id="count1">

下面是我试图获取该值的http GET请求中所包含的内容

<input type="hidden" name="bought" value=document.getElementById("count1").value; />

在结果网址中,这是相关参数 '&bought = document.getElementById%28“ count1”%29.value%3B'

enter image description here

2 个答案:

答案 0 :(得分:1)

这是吗?

   type age income   avg
1     1  41   1000  2000
2     1  42   3000  2000
3     1  43     NA  3000
4     1  44     NA  6000
5     1  45   6000  6000
6     1  46     NA  7000
7     1  47   8000  8000
8     1  48     NA  9000
9     1  49  10000 10500
10    1  50  11000 10500
11    2  41     NA  2000
12    2  42   2000  2000
13    2  43     NA  3000
14    2  44   4000  4000
15    2  45     NA  5500
16    2  46   7000  8000
17    2  47   9000  8000
18    2  48     NA  9000
19    2  49     NA   NaN
20    2  50     NA   NaN
let c1 = document.querySelector("#count1");
let c2 = document.querySelector("#count2");

c1.onchange = function(){
  c2.type = "text";
  c2.value = c1.value;
}

或者,用<input type="text" name="list_quantity" value="1" id="count1"> <input type="hidden" name="bought" id="count2"/>

onkeyup
let c1 = document.querySelector("#count1");
let c2 = document.querySelector("#count2");

c1.onkeyup = function(){
  c2.type = "text";
  c2.value = c1.value;
}

答案 1 :(得分:0)

您可以通过以下方式进行操作:

function change(){
        document.getElementById('bought').value = document.getElementById('count1').value;
    }
<input type="hidden" name="bought" id="bought" />
<input onchange="change()" type="text" name="list_quantity" value="1" id="count1">