<form> <input type="text" id='username'> <button type="button" id='save' onclick="save()">保存</button> </form> <script> function save(){ var name = document.getElementById('username').value; alert(name); if(name=='hello'){ history.go(-1); } else{ alert('输入错误 hello'); } } </script>
函数名称换个
<form> <input type="text" id='username'> <button type="button" id='save' onclick="save1()">保存</button> </form> <script> function save1(){ var name = document.getElementById('username').value; alert(name); if(name=='hello'){ history.go(-1); } else{ alert('输入错误 hello'); } } </script>真的是啊
不能同名!
<form> <input type="text" id='username'> <button type="button" id='save' onclick="save()">保存</button> </form> <script> function save(){ var name = document.getElementById('username').value; alert(name); if(name=='hello'){ history.go(-1); } else{ alert('输入错误 hello'); } } </script>
函数名称换个
<form> <input type="text" id='username'> <button type="button" id='save' onclick="save1()">保存</button> </form> <script> function save1(){ var name = document.getElementById('username').value; alert(name); if(name=='hello'){ history.go(-1); } else{ alert('输入错误 hello'); } } </script>在form里save被当成了 onclick="console.log(save);" 把save打印出来看下就知道了
在form里save被当成了 onclick="console.log(save);" 把save打印出来看下就知道了
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号