所以我有一個獲取學生 ID 和姓名的表單,將其存盤在 JSO 檔案中,然后在單擊按鈕時自動顯示它。但現在我希望表單過濾學生的回應,以便學生只能輸入整數作為 id 和字串作為名稱
async function addStudent() {
const url = server '/students';
const student = {id: studentId, name: studentName};
const options = {
method: 'POST',
headers: {
'Content-Type' : 'application/json'
},
body: JSON.stringify(student)
}
const response = await fetch(url, options);
}
我嘗試到處搜索,但找不到任何東西
uj5u.com熱心網友回復:
當您的按鈕被按下時,我會在通過您的發布請求之前檢查您的值。格式如下:
if (isNaN(form.studentId.value) && !(isNaN(form.name.value))) {
addStudent();
} else {
alert("Invalid form!");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/446380.html
標籤:javascript 节点.js json
