我当前正在创建一个搜索页,可以在其中通过ID获取用户的个人资料。
这是我的JADE表单,我在其中放置了用户的ID,然后提交表单以发送帖子:
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>List Funcionários</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" type="text/css" media="screen" href="/admin/css/main.css"/>
</head>
<body>
<header class="header">
<h1 id="title" class="inline"><img id="logo" src="/admin/image/logo4.png" alt="Image failed to load" class="inline"/>User Med</h1>
<h2 id="stitle">Search User</h2>
</header>
<div class="do">
<form id="search-theme-form" action="/profileuser/" accept-charset="UTF-8" method="get" name="search-theme-form" class="myDform">
<label>User ID:
<input id="inputDoc" name="id" required="" value="" type="text" class="input"/>
</label>
<input value="Submit" type="submit"/>
</form>
</div>
<script src="./admin/scripts/profileuser.js"></script>
</body>
</html>
这是我的JS代码,在这里我尝试获取输入值并将表单操作/profileuser/
更改为/profileuser/"userid"
:
let docid = document.getElementById('inputDoc').value;
let form = document.getElementsByClassName('myDform');
form.addEventListener('submit', submit);
function chgAction(){
alter(docid)
form.chgAction = docid.value;
}
function submit (e){
chgAction();
}
问题是我不能仅从输入中获得用户ID,而是获得?id= "userid"
。
答案 0 :(得分:1)
已更改
form.chgAction = docid.value;
与
form.action = form.action+docid.value;
document.getElementById('search-theme-form').addEventListener('submit',chgAction);
function chgAction(){
let docid = document.getElementById('inputDoc');
let form = document.getElementById('search-theme-form');
form.action= form.action+docid.value;
console.log("path after: "+form.action);
}
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>List Funcionários</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" type="text/css" media="screen" href="/admin/css/main.css"/>
</head>
<body>
<header class="header">
<h1 id="title" class="inline"><img id="logo" src="/admin/image/logo4.png" alt="Image failed to load" class="inline"/>User Med</h1>
<h2 id="stitle">Search User</h2>
</header>
<div class="do">
<form id="search-theme-form" action="/profileuser/" accept-charset="UTF-8" method="get" name="search-theme-form" class="myDform">
<label>User ID:
<input id="inputDoc" name="id" type="text" class="input" required/>
</label>
<input value="Submit" type="submit"/>
</form>
</div>
</body>
</html>