我试图让这个表单在提交时执行这个功能,但由于某种原因,它会弹出警报,然后刷新整个页面。我尝试过其他在线解决方案,例如:防止表单重定向或提交时刷新?
但这没有用。
function addFood() {
alert("123");
return false;
}
<form onsubmit="return addFood()" data-ajax="false">
<input type="text" name="" id="name" value="" placeholder="name" data-clear-btn="true"/>
<input type="text" name="" id="brand" value="" placeholder="brand" data-clear-btn="true"/>
<input type="text" name="" id="extra" value="" placeholder="extra" data-clear-btn="true"/>
<input type="number" name="" id="amount" value="" placeholder="amount" data-clear-btn="true"/>
<input type="number" name="" id="calories" value="" placeholder="calories" data-clear-btn="true"/>
<input type="number" name="" id="fat" value="" placeholder="fat" data-clear-btn="true"/>
<input type="number" name="" id="carbohydrate" value="" placeholder="carbohydrate" data-clear-btn="true"/>
<input type="number" name="" id="fibre" value="" placeholder="fibre" data-clear-btn="true"/>
<input type="number" name="" id="sugar" value="" placeholder="sugar" data-clear-btn="true"/>
<input type="number" name="" id="protein" value="" placeholder="protein" data-clear-btn="true"/>
<input type="submit" value="submit"/>
<form>