<a href="#" onclick=""> 不能不知道的技巧

在一个超链接中 可以使用href 和onlick,有时要在A的标记同时使用,在同时使用时,有时让href起作用或者失效,那么如何设计呢?

使用javascript的时候,通常我们会通过类似:
<a href="#" onclick="javascript:方法">提交</a>
的方式,通过一个伪链接来调用javascript方法.

这种方法有一个问题是:
虽然点击该链接的时候不会跳转页面.但是滚动条会往上滚,解决的办法是返回一个false.
如下所示:


<a href="#" onclick="javascript:方法;return false;">提交</a>

有时恰好要利用锚记功能,再比如 给Micolog博客加简单的回复功能所使用的代码

<a href="#commentarea" onclick="return backcomment('{{comment.author}}');">回复</a>

//回复自动输入姓名函数
function backcomment(msg){
backdb=document.getElementById('comment');
backdb.value="@"+msg;
return true;
}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> <html> <head id="Head1"> <title> 领丰集团--MES </title> <link href="Inc/Css/login/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="Inc/Css/login/css/ace.min.css" rel="stylesheet" type="text/css" /> <link href="Inc/Css/login/css/ace-rtl.min.css" rel="stylesheet" type="text/css" /> <link href="Inc/Css/login/css/icon.css" rel="stylesheet" type="text/css" /> <!--[if lte IE 8]> <link rel="stylesheet" type="text/css" href="Inc/Css/login/css/ace-ie.min.css" /> <![endif]--> <script src="Inc/Js/Plugs/jQuery/jquery.min.js" type="text/javascript"></script> <script src="Inc/Js/Plugs/jquery/jquery.cookie.js" type="text/javascript"></script> <script type="text/javascript" src="Inc/Js/LoginService.js"></script> <script type="text/javascript"> //如果为移动设备自动转址到设动版 $(document).ready(function () { //return; var href = window.location.href; var v_loginame = $.cookie("loginame"); //若存在用户名cookie if (v_loginame) { $("#uid").val(v_loginame); $("#uid").focus(); //接收从main页面返回的error =1错误信息,并弹出! if (href.indexOf("error=1") != -1)at $("#errormsg").html("请求已超时,请重新登入MES系统!"); } else $("#uid").focus(); //键盘确认时进行登陆验证 document.onkeydown = function (e) { var ev = window.event || e; if (ev.keyCode == 13) { CheckLogin(); } }; $("#btnPassword").click(GetPassword); $("#resetpassword").click(ResetPassword); }); window.onload = function () { var href = window.location.href; var uid, pwd; //SSO转向JXC登录验证 if (href.indexOf("UID=") > -1 && href.indexOf("PWD=") > -1) { uid = AccountLogin.Base64ToString(href.split("UID=")[1].split("&")[0]).value; pwd = AccountLogin.Base64ToString(href.split("PWD=")[1].split("&")[0]).value; $("#uid").val(uid); //验证是否有动态密码验证 CheckType(); $("#pwd").val(pwd); CheckLogin(); } }; //验证账号或口令卡 function CheckLogin() { var loginame, pwd, dypasswd, ret, p_issso, p_isdpt, p_isOpenDpt, p_isUseOpt; loginame = $("#uid").val(); if (loginame.length == 0) { $("#accounterror").html("账号不能为空!"); return; } pwd = $("#pwd").val(); if (pwd.length == 0) { $("#passworderror").html("密码不能为空"); return; } //取得sso的验证开关 p_issso = AccountLogin.GetConfigSet("IsSSOValid").value; if (p_issso != "0") { dypasswd = $("#dypasswd").val(); p_isUseOpt = AccountLogin.IsValidOtp(loginame).value; if (p_isUseOpt.split(&#39;,&#39;)[0] == "Y" && dypasswd.length == 0) { $("#passworderror").html("账号:" + loginame + "已启用动态密码验证,动态密码不能为空!"); return; } ret = AccountLogin.CheckSSOLogin(loginame, pwd, dypasswd).value; var key = ret.split(","); if (key[0] == "Y") { checkBILogin(p_issso); } else { //口令与密码验证不通过时 $("#dypasswd").val(""); if (key.length > 0) { $("#pwd").val("").focus(); alert(key[1]); } return; } } else { checkBILogin(p_issso); } } function onloadUI() { var wh = ($(window).width() - 725) / 2; $("#loginbanner").animate({ left: wh }, 0); $("#downdiv").animate({ left: 55 }, 0); $("#person").animate({ left: wh }, 0); window.setTimeout("LoadPanner()", 100); // showNote(); } function LoadPanner() { var wh = ($(window).width() + 100) / 2; $("#loginpanner").animate({ left: wh }, 0); } function CancelLogin() { $("#uid").val("").focus(); $("#pwd").val(""); } function ResetLogin(p_button) { if (p_button.reset) { p_button.reset.style.display = "block"; } else { var v_div = document.createElement(&#39;div&#39;); p_button.parentNode.appendChild(v_div); p_button.reset = v_div; v_div.style.position = "absolute"; v_div.style.top = p_button.offsetTop + p_button.offsetHeight + "px"; v_div.style.left = "0px"; v_div.style.width = "100%"; v_div.style.height = "90px"; v_div.style.paddingTop = "3px"; var v_iframe = document.createElement(&#39;iframe&#39;); v_div.appendChild(v_iframe); v_iframe.src = "Reset.aspx"; v_iframe.style.width = "100%"; v_iframe.style.height = "100%"; v_iframe.style.border = "solid 1px #90D1F1"; v_iframe.style.overflow = "hidden"; } p_button.blur(); } function Printhelp() { var url = " http://" + document.URL.split(&#39;/&#39;)[2] + "/sso/Inc/help/printhelp.doc"; window.location.href = url; } //用户验证方式检测 function CheckType() { var loginame = $("#uid").val(); if (loginame == "") { //初始化 retset(); return; } var p_isdpt = AccountLogin.GetConfigSet("IsDPWValid").value; //开启动态口令卡验证 if (p_isdpt == "1") { ret = AccountLogin.IsValidOtp(loginame).value; if (ret.split(&#39;,&#39;)[0] == "Y") { $("#dypasswd,#dyptext").show(); } else $("#dypasswd,#dyptext").hide(); } loadFact(loginame); } function loadFact(loginame) { $("#factno").empty(); $("#errormsg").html(""); var fxml = AccountLogin.GetFactList(loginame).value; if (fxml.replace("<NewDataSet />", "").length == 0) { $("#errormsg").html("请选择登陆厂别!"); return; } var option = ""; if ($.browser.msie) { var XMLDom = new ActiveXObject("Microsoft.XMLDOM"); XMLDom.loadXML(fxml); } else XMLDom = fxml; $(XMLDom).find("Data").each(function () { option += "<option value=&#39;" + $(this).find(&#39;FACTNO&#39;).text().trim() + "&#39;>" + $(this).find(&#39;FACTNAME&#39;).text() + "</option>"; }); $("#factno").append(option); $("#factno").find("option[0]").attr("selected", true); } function retset() { $("#uid").val("").focus(); $("#pwd").val(""); $("#dypswd,#dypswdvalue").hide(); } function show_box(id) { $(&#39;.widget-box.visible&#39;).removeClass(&#39;visible&#39;); $(&#39;#&#39; + id).addClass(&#39;visible&#39;); } function GetPassword() { var email = $("#useremail").val(); var type = "false"; if ($.trim(email).length > 0) { if (isEmail(email)) { type = "true"; } $.ajax({ type: "POST", async: false, dataType: "text", cache: false, url: "UI/Handler.ashx", data: { MothodName: "Email", p_email: email, p_type: type }, contentType: "application/x-www-form-urlencoded", error: function (xhr, ajaxOptions, thrownError) { window.document.write(xhr.responseText + thrownError); }, success: function (res) { alert(res); } }); } else alert("请输入账号或邮件地址!"); } function isEmail(str) { var reg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/; return reg.test(str); } function ResetPassword() { var r_message = ""; var v_old = document.getElementById(&#39;old&#39;), v_new = document.getElementById(&#39;new&#39;); if (v_old.value == "" || v_new.value == "") { alert("输入密码不能为空值!"); return; } if (v_old.value != v_new.value) { alert("输入密码不一致!"); return; } $.ajax({ type: "POST", async: false, dataType: "text", cache: false, url: "UI/Handler.ashx", data: { MothodName: "Update", p_hash: request["hash"], p_pwd: v_old.value }, contentType: "application/x-www-form-urlencoded", error: function (xhr, ajaxOptions, thrownError) { window.document.write(xhr.responseText + thrownError); }, success: function (res) { r_message = res; } }); if (r_message) { alert("密码重置成功!"); window.location.assign("Login.aspx"); } else { alert("密码重置失败,请联通络系统维护人员!"); } } function CheckOS() { var x = navigator.userAgent.match(/x86_64|Win64|WOW64/) || navigator.cpuClass === &#39;64&#39; ? &#39;64&#39; : &#39;32&#39;; if (x == "64") { $("#printDownload").html(&#39;[ <a name="Alang" id="A1" href="/lfxj/slPrint_x64V2.1_aliyun.zip">报表列印控件下载</a> ]&#39;); $("#ExplorerDownload").html(&#39;[ <a name="Alang" id="A1" href="/lfxj/chrome64.exe">浏览器下载</a> ]&#39;); } else { $("#printDownload").html(&#39;[ <a name="Alang" id="A2" href="/lfxj/slPrint_x86V2.1_aliyun.rar">报表列印控件下载</a> ]&#39;); $("#ExplorerDownload").html(&#39;[ <a name="Alang" id="A2" href="/lfxj/chrome32.exe">浏览器下载</a> ]&#39;); } } </script> <style type="text/css"> .login-layout { background: url(&#39;Inc/Css/login/css/img/bg/bg-05.jpg&#39;) #f3f3f3; } .login-container { width: 500px; margin: 0px auto; margin-top: 2%; } .login-layout .widget-box { visibility: hidden; position: absolute; overflow: hidden; width: 100%; border-bottom: 0px; box-shadow: none; padding: 6px; background-color: #fff; -webkit-transform: scale(0, 1) translate(-150px); } .error { color: Red; } </style> </head> <body class="login-layout" onload="CheckOS()"> <form name="form2" method="post" action="./login.aspx?ReturnUrl=%2flfxj%2fMain.aspx%3fuid%3dlfit002%26pwd%3d251289&error=1" id="form2"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MzM0MzM0MDBkZOHjsIIU57s89WK6gN8Mco90VTSSMfOvi5xlFACzUNlb" /> <script type="text/javascript" src="/lfxj/ajaxpro/prototype.ashx"></script> <script type="text/javascript" src="/lfxj/ajaxpro/core.ashx"></script> <script type="text/javascript" src="/lfxj/ajaxpro/converter.ashx"></script> <script type="text/javascript" src="/lfxj/ajaxpro/AccountLogin,App_Web_cbhnaljf.ashx"></script> <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="EEDA5EB3" /> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAIxWz1UdzUxzn5dgMn23JQTWSBi3t7AiBe0pTmtLU9og20iuEUbb0xsJDsF2zq1w8jftRNcTcPUX+wGarsyFFCf" /> <div class="login-container"> <div class="center"> <h1> <i class="icon-leaf green"></i><span class="red">LFMES</span> <span class="white">领丰电子--MES</span> </h1> <h4 class="blue"> © LinFeng CO.LTD</h4> </div> <div class="space-6"> </div> <div class="position-relative"> <div id="login-box" class="login-box visible widget-box no-border"> <div class="widget-body"> <div class="widget-main"> <h4 class="header blue lighter bigger"> <i class="icon-coffee green"></i>请输入您的账号密码 </h4> <fieldset> <label class="block clearfix"> <span class="block input-icon input-icon-right">账号: <input type="text" id="uid" class="form-control" onblur="CheckType();" value="xctest" /> <i class="icon-user"></i></span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right">密码: <input type="password" id="pwd" class="form-control" value="" /> <i class="icon-lock"></i></span> </label> <label class="block clearfix" > <span class="block input-icon input-icon-right">公司: <select id="factno" class="form-control"> </select> </span> <span class="block input-icon input-icon-right" style="display:none"> <input type="radio" name="profact_mk" checked value="1" style="display:none"/> </span> <span id="errormsg" class="error"></span> </label> <label class="block clearfix" style="display:none"> <span class="block input-icon input-icon-right" id="dypwd"> <label id="dyptext" style="display: none"> 动态密码:</label> <input type="password" id="dypasswd" style="display: none" class="form-control" value="" /> <i class="icon-lock"></i></span> </label> <div class="clearfix"> <div id="div_lang"> <label><input type="radio" name="lang" checked="checked" value="zh"/><font color="red"> [ 中文 ]</font></label>   <p class="divDownload"> <span id="ExplorerDownload"></span> </p> <p class="divDownload"> <span id="printDownload"></span> </p> </div> <input name="Login" type="button" id="Login" class="width-35 pull-right btn btn-sm btn-primary" value="登入" onclick="CheckLogin()" /> </div> <div class="space-4"> </div> </fieldset> </div> <div class="toolbar clearfix"> </div> </div> </div> <div id="forgot-box" class="forgot-box widget-box no-border"> <div class="widget-body"> <div class="widget-main"> <h4 class="header red lighter bigger"> <i class="icon-key"></i>取回密码 </h4> <div class="space-6"> </div> <fieldset> <label class="block clearfix"> <span class="block input-icon input-icon-right">请输入账号或Email: <input id="useremail" class="form-control" /> <i class="icon-envelope"></i></span> </label> <div class="clearfix"> <button type="button" id="btnPassword" class="width-35 pull-right btn btn-sm btn-danger"> <i class="icon-lightbulb"></i>发 送 </button> </div> </fieldset> </div> <div class="toolbar center"> <a href="#" onclick="show_box(&#39;login-box&#39;); return false;" class="back-to-login-link"> 返回登录 <i class="icon-arrow-right"></i></a> </div> </div> </div> <div id="signup-box" class="signup-box widget-box no-border"> <div class="widget-body"> <div class="widget-main"> <h4 class="header green lighter bigger"> <i class="icon-group blue"></i>新用户注册 </h4> <div class="space-6"> </div> <fieldset> <label class="block clearfix"> <span class="block input-icon input-icon-right">账号: <input type="email" class="form-control" /> <i class="icon-envelope"></i></span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right">邮箱: <input type="email" class="form-control" /> <i class="icon-envelope"></i></span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right">姓名: <input type="text" class="form-control" /> <i class="icon-user"></i></span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right">密码: <input type="password" class="form-control" /> <i class="icon-lock"></i></span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right">请重新输入一次密码: <input type="password" class="form-control" /> <i class="icon-retweet"></i></span> </label> <div class="space-24"> </div> <div class="clearfix"> <button type="reset" class="width-30 pull-left btn btn-sm"> <i class="icon-refresh"></i>重置 </button> </div> </fieldset> </div> <div class="toolbar center"> <a href="#" onclick="show_box(&#39;login-box&#39;); return false;" class="back-to-login-link"> <i class="icon-arrow-left"></i>返回登录</a> </div> </div> </div> <div id="reset-box" class="forgot-box widget-box no-border"> <div class="widget-body"> <div class="widget-main"> <h4 class="header red lighter bigger"> <i class="icon-key"></i>重置密码 </h4> <div class="space-6"> </div> <fieldset> <label class="block clearfix"> <span class="block input-icon input-icon-right">新密码: <input id="old" class="form-control" type="password" /> <i class="icon-envelope"></i></span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right">确认密码: <input id="new" class="form-control" type="password" /> <i class="icon-envelope"></i></span> </label> <div class="clearfix"> <button type="button" id="resetpassword" class="width-35 pull-right btn btn-sm btn-danger"> <i class="icon-lightbulb"></i>确 定 </button> </div> </fieldset> </div> <div class="toolbar center"> <a href="#" onclick="show_box(&#39;login-box&#39;); return false;" class="back-to-login-link"> 返回登录 <i class="icon-arrow-right"></i></a> </div> </div> </div> </div> </div> </form> </body> </html> <!--[if IE 6]> <script type="text/javascript"> DownIE8(); </script> <![endif]-->我打算用postman做接口测试,帮我找出这个网页得接口
最新发布
09-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值