如何在javascript中使用get方法
我试图用get方法生成一个表单,但我遇到了一个问题。我不知道如何得到这个值。我做这个代码,但不工作,我不明白为什么 我知道这段代码非常简单,但我想了解如何使用get方法: document.querySelectorbutton.addEventListenerclick,函数{ console.log'Click détecté'; var form=document.createElement'form'; setAttribute'method','GET'; setAttribute'action','test1.php'; document.body.appendChildform; 让monSelect=document.createElement'select'; 让monOption=document.createElement'option'; 设置属性“值”,1; monOption.innerText='choice1'; monSelect.appendment; 让monOption2=document.createElement'option'; monOption2.setAttribute'value',2; monOption2.innerText='choice2'; monSelect.Appendment2; form.appendChildmonSelect; 让输入=document.createElement“输入” 输入.setAttribute'type',提交; 输入.setAttribute'value',提交; 表单输入; } ; 奎尔克语 阿琼块如何在javascript中使用get方法,javascript,php,Javascript,Php,我试图用get方法生成一个表单,但我遇到了一个问题。我不知道如何得到这个值。我做这个代码,但不工作,我不明白为什么 我知道这段代码非常简单,但我想了解如何使用get方法: document.querySelectorbutton.addEventListenerclick,函数{ console.log'Click détecté'; var form=document.createElement'form'; setAttribute'method','GET'; setAttribute'a
你快到了。对于要提交的表单元素,它需要具有name属性。您只需添加
monSelect.setAttribute('name', 'premier');
然后将查询字符串添加到GET请求中,如下所示:
https://stacksnippets.net/test1.php?premier=1
document.querySelectorbutton.addEventListenerclick,函数{
console.log'Click détecté';
var form=document.createElement'form';
setAttribute'method','GET';
setAttribute'action','test1.php';
document.body.appendChildform;
让monSelect=document.createElement'select';
monSelect.setAttribute'name','premier';
让monOption=document.createElement'option';
设置属性“值”,1;
monOption.innerText='choice1';
monSelect.appendment;
让monOption2=document.createElement'option';
monOption2.setAttribute'value',2;
monOption2.innerText='choice2';
monSelect.Appendment2;
form.appendChildmonSelect;
让输入=document.createElement“输入”
输入.setAttribute'type',提交;
输入.setAttribute'value',提交;
表单输入;
}
;
奎尔克语
阿琼块