javascript的问题:return false无法正常工作 [英] problem with javascript: return false is not working

查看:165
本文介绍了javascript的问题:return false无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我的程序中有一个链接如图所示,然后点击它调用函数clearform,如下所示:

Hey there is a link in my program as shown and onclick it calls the function clearform as shown:

Html代码:

<a class="button" href="Cancel" style="left: 55%;" onclick="clearForm()">Cancel</a>

JavaScript代码:

JavaScript Code:

function clearForm(){
        document.getElementById("subjectName").value = "";
        return false;
    }

返回false在此代码中无效。实际上函数的第一行成功执行但返回false失败。我的意思是页面被重定向到网址取消。

return false is not working in this code. actually the first line of the function executed successfully but the return false was failed. I mean page is redirected to url "Cancel".

推荐答案

将您的代码更改为

<a class="button" href="Cancel" onclick="return clearForm()">Cancel</a>

这篇关于javascript的问题:return false无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆