
当html中的
理解HTML按钮的默认行为
在HTML中,
例如,考虑以下HTML结构和JavaScript代码:
Button Behavior Example No Player Names Loaded
const gatherPlayersButton = document.getElementById('gatherNames');const areaForPlayerNames = document.getElementById('playerNamesGoHere');const summon_players = () => { // ... 获取输入值并构建请求字符串 ... let eR = document.getElementById('expertiseReq').value || "None"; let lR = document.getElementById('locationReq').value || "None"; let tagsString = eR + "," + lR; fetch(`/battle?tags=${tagsString}`, { method: "GET" }) .then((response) => response.text()) .then((text) => { areaForPlayerNames.innerText = text; });};gatherPlayersButton.addEventListener("click", () => summon_players());
在这种情况下,gatherNames按钮独立于任何表单,其click事件会正常触发summon_players函数,并通过fetch请求更新blockquote中的内容。
然而,如果我们将输入字段和按钮用
以上就是深入理解HTML表单中按钮的默认行为及其控制的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1584311.html
微信扫一扫
支付宝扫一扫