gpt4 book ai didi

javascript - 如何在没有 ?"name"= "value"的情况下从 HTML/JADE 输入中获取值

转载 作者:行者123 更新时间:2023-11-30 20:25:44 25 4
gpt4 key购买 nike

我目前正在创建一个搜索页面,我可以在其中通过 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"

最佳答案

改变

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>

关于javascript - 如何在没有 ?"name"= "value"的情况下从 HTML/JADE 输入中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50956696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com