在对话框<div>中的消息中添加新行

jay*_*Ann 3 html javascript jquery

只是想问一下如何将消息放在另一行之后.这是我程序中的代码:

function isEmpty(field,name,minVal, maxVal){
  var msg ="";
  if (field.val() >= minVal || field.val() <= maxVal){
    if ( field.val().length == 0){ 
      msg=(name + ' is empty.\n');
    }
  }
  else{
    msg=(name + ' inputted is invalid or number is more than 1000. \n');
  }  
  return msg;
}

function validateTallyReq(par){
  var msg= "Please read the following:";

  msg += isEmpty($('#tallyPlankNo'),'Plank Number ',1,999) ;        
  msg += isEmpty($("#tallyThick"), 'Thickness value',.9,999);
  msg += isEmpty($("#tallyWidth"), 'Width Value',.9,999);
  msg += isEmpty($("#tallyLength"), 'Lenght Value',.9,999);
  msg += isEmpty($("#tallyQty"), 'Quantity',1,3);

  if (msg == "")  { 

  } else {
    showMessage(msg);    
  }
  return false; 
}
Run Code Online (Sandbox Code Playgroud)

这会在一行中输出消息.我想要的是要输出的消息,如:

Please read the following:

Plank Number is empty. 
Thickness value is empty. 
Width Value is empty. 
Lenght Value inputted is invalid or number is more than 1000. 
Quantity is empty. 
Run Code Online (Sandbox Code Playgroud)

还有一个问题,我真的不知道为什么它显示长度值无效,虽然我不输入任何值,.请帮忙.

编辑
这是我的showMessage函数:

function showMessage(msg) {
  $('#dialog #message').text(msg);
  $('#dialog').dialog('open');
}
Run Code Online (Sandbox Code Playgroud)

bbg*_*bbg 8

尝试<br/>在每行后添加一条消息.如果该show()方法正在执行类似的操作,那将会有效$("#displaydiv").html(msg);

msg += "<br/>";
Run Code Online (Sandbox Code Playgroud)

至于意外的invalid消息,看起来这个条件中的逻辑是错误的:

if (field.val() >= minVal || field.val() <= maxVal)
Run Code Online (Sandbox Code Playgroud)

尝试制作它

if (field.val() >= minVal && field.val() <= maxVal)
Run Code Online (Sandbox Code Playgroud)