js remove all html tags and the string & nbsp symbol de spaces

1. html tag string is removed

function delHtmlTag(str){
  return str.replace(/<[^>]+>/g,"");
}

2. & nbsp removing space characters in the string

/*去掉空格符*/
function rejectnbsp(value) {
       var value = String(value);
       if(value.indexOf("nbsp") != -1){
           value = value.replace(/&nbsp;/ig, "");
       }
       return Number(value);
   }
var test = "this &nbsp; is &nbsp; a test";
test = test.replace(/&nbsp;/ig, "");
alert(test);

3. js call the function specified period

var count = 0;
var timePromise = window.setInterval(function(){
    count++;
    alert(count);
    if (count == 100) {
        // 停止
        window.clearInterval(timePromise);
    }
},1000);

Method 4. windos

// 刷新页面
window.location.reload();
// 跳转页面
window.location=url;
window.location.href=url;
// 父页面刷新 一般由window.open()打开的页面的父页面
window.opener.reloadGrid();
// 打开一个新页面加载
window.open(url);

5. disabled attribute using

// 两种方法设置disabled属性
$('#areaSelect').attr("disabled",true);
$('#areaSelect').attr("disabled","disabled");

// 三种方法移除disabled属性
$('#areaSelect').attr("disabled",false);
$('#areaSelect').removeAttr("disabled");
$('#areaSelect').attr("disabled","");

6. display hidden elements

$(obj).css("display","none");

7. parameters to obtain the address bar

function getParams(name){
  var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  var r = window.location.search.substr(1).match(reg);
  if(r!=null)return  unescape(r[2]); return null;
}
Published 172 original articles · won praise 0 · Views 5688

Guess you like

Origin blog.csdn.net/weixin_44635157/article/details/104894294