• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
秦大田的院子
博客园    首页    新随笔    联系   管理    订阅  订阅
前端的几个技巧

一、文字输入回车转换为--<br />
var text = $('.wra').html();
text=text.replace(/[\n\r]/g,'<br>')
$('.wra').html(text);

二、手机端跳转
onclick="location.href ='/html/html.html?doctor=' + doctorId"

三、移除点击事件
$(".apply").attr("onclick","apply();"); attr("事件","方法名")
$(".apply").removeAttr("onclick");

四、超出隐藏--选择几行:
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
---单行---
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

五、正则
/^(?=.*\d)[a-z\d]{6,20}$/i 判断 6到20字符

六、判断网络
if(window.navigator.onLine==true) { 
    alert("首次 -- 已连接"); 这个可以,但是没有网络怎样加载js啊
  }else { 
    alert("首次 -- 未连接");
}

七、判断后台返回img错误调用img(图片)
onerror="nofind();"
function nofind(){
var img=event.srcElement;
img.src="/images/onerror.png";
img.onerror=null; //控制不要一直跳动
}
<img src="onerror.png" alt="" class="surface_plot" onerror="src='onerror.png'" />

八、判断val值为空
$(function() {
$(".searchbox").blur(function() {
if ($(".searchbox").val() == ""){
$(".searchbox").focus();
}else
alert($(".searchbox").val());
});
});

九、要检查是否是可见的元素,你可以使用下面的代码片段:
if($(element).is(":visible") == "true")
{
//可见
}
else
{
//不可见
}

十、设置计时器
$(document).ready(function(){

window.setTimeout(function(){
// 执行代码
}, 500);

});
---------------------

原文:https://blog.csdn.net/qq_38881495/article/details/81211715

posted on 2019-08-02 15:38  秦大田的院子  阅读(127)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3