2016-10-04 130 views
1

我點擊一個按鈕後顯示一個警告框,但字符串文本正在關閉。爲什麼我的警報框不顯示正確的文本?

這是我的代碼:

jQuery('input[name="addtocart"]').each(function() 
{ 
    jQuery(this).on("click", function(event) 
    { 
     qty = jQuery(this).parent().find('input[name="qty"]').val(); 
     var qty1 = parseFloat(qty); 
     qth = jQuery(this).parent().parent().find('.qtyonhand').text(); 
     var qth1 = parseFloat(qth); 
     itemName = jQuery(this).parent().parent().parent().find('.cell-desc   
     span').text(); 
     if(qty1 > qth1){ 
      alert("For the following item, the ordered quantity exceeds the 
      current available quantity.Please adjust the quantity and 
      retry.\n"+itemName+"-"+"Available Qty:"+qth1); 
     } 
    }); 
}); 

這裏是圖像:

Alert Message

在上述圖像,可用性文本顯示在下一行。 如何在單行顯示字符串?請幫忙。

+0

使用'... + itemName.trim() +「 - 」+「可用...' – adeneo

+0

感謝它的工作正常 –

回答

1

看來你需要用空格替換換行符。 的if語句之前添加以下代碼:

itemName = itemName.replace(/\n/g, " "); 

正則表達式來自this thread

0
if(qty1 > qth1){ 
    alert("For the following item, the ordered quantity exceeds the 
    current available quantity.Please adjust the quantity and  
    retry."+itemName+"-"+"Available Qty:"+qth1); 
} 

請從警報的內容中刪除\ n

相關問題