2014-09-21 4 views
2

Я хочу очистить заголовок диалога, но $('#dialog').dialog('option', 'title', ' '); не работает должным образом, это сделает заголовок диалога очень тонким, что является правильным способом очистить заголовок?jQuery UI: как сбросить название диалогового окна?

<!doctype html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>jQuery UI Dialog - Default functionality</title> 
     <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/cupertino/jquery-ui.css"/> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> 
     <script> 
      $(function() { 
       $("#b1").click(function(){ 
        $('#dialog').dialog('option', 'title', 'test'); 
       }); 
       $("#b2").click(function(){ 
        $('#dialog').dialog('option', 'title', ' '); 
       }); 
       $("#b3").click(function(){ 
        alert($('#dialog').dialog('option', 'title')); 
       }); 
       $("#dialog").dialog(); 
      }); 
     </script> 
    </head> 
    <body> 
     <div id="dialog"> 
      <p>This is a dialog.</p> 
     </div> 
     <input id='b1' type='button' value='set title to test'> 
     <input id='b2' type='button' value='clear title'> 
     <input id='b3' type='button' value='alert(title);'> 
    </body> 
</html> 

ответ

2

Просто вставьте non breaking space, а не просто space. Я скопирую/впечатаю его со страницы википедии:

U + 2007 площадь рисунка (HTML: & # 8199;). Производит пространство, несколько равное цифрам (0-9).

я сделать интерактивный образец:

  $(function() { 
 
       $("#b1").click(function(){ 
 
        $('#dialog').dialog('option', 'title', 'test'); 
 
       }); 
 
       $("#b2").click(function(){ 
 
        $('#dialog').dialog('option', 'title', ' '); 
 
       }); 
 
       $("#b3").click(function(){ 
 
        alert($('#dialog').dialog('option', 'title')); 
 
       }); 
 
       $("#dialog").dialog(); 
 
      });
 <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/cupertino/jquery-ui.css"/> 
 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> 
 
     
 
     <div id="dialog"> 
 
      <p>This is a dialog.</p> 
 
     </div> 
 
     <input id='b1' type='button' value='set title to test'> 
 
     <input id='b2' type='button' value='clear title'> 
 
     <input id='b3' type='button' value='alert(title);'>

+1

Спасибо, это работает! Я фактически попробовал еще один символ Юникода, прежде чем публиковать этот вопрос, но он не сработал, этот делает магию. – agou

Смежные вопросы