简体   繁体   English

使用JavaScript或jQuery向'div'添加/传递引导类

[英]Adding/passing bootstrap class to the 'div' using javascript or jQuery

Folks!! 伙计们!

I am developing a website, in that showing the field errors in javascript alert() 我正在开发一个网站,该网站在javascript alert()中显示字段错误

User is not satisfy with the alert pop-up each time, and I thought to provide it in inline div block 用户对警报弹出窗口的每次使用都不满意,我想在嵌入式div块中提供它

I want to know how I can pass/add bootstrap class property{ alert alert-warning } to the error block when I am passing Error Message from the javascript or jquery. 我想知道当我从javascript或jquery传递错误消息时如何将bootstrap类属性{ alert alert-warning }传递/添加到错误块。

function getValidateField(){
  var varName= document.getElementById('txtNameSetting').value;
  if(varName.trim().length <= 0){
    //alert("Please enter Application Name");
    document.getElementById('divErrorBlock').innerHTML = "Please enter Application Name";
    document.getElementById('divErrorBlock').style.display = 'block';
    //$('#divErrorBlock').show(); 
    return false;
  }
  else return true;
}

If I pass inside the 'div', it will visible all the time, I need to hide this blcok until it get invoke 如果我在'div'内部传递,它将一直可见,我需要隐藏此blcok直到被调用

Thank in advance 预先感谢

Try setAttribute; 尝试setAttribute;

document.getElementById('divErrorBlock').setAttribute("class", "alert alert-warning");

or jquery addClass() 或jQuery addClass()

$('#divErrorBlock').addClass('alert alert-warning');

or using attr() 或使用attr()

 $('#divErrorBlock').attr('class','alert alert-warning');

If you can use jquery. 如果可以使用jquery。 It is as simple as this. 就这么简单。

$('#divErrorBlock').addClass('alert alert-warning');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM