10

テキストの中央揃えでJavascriptアラートボックスに3行のテキストを表示したいと思います。

そのために次のコードを使用しています、

alert(
    '\t\t\t\t'+"Congratulations!" + '\n\t' +
    "You are now subscribed with test.com!" + '\n' +
    "Keep on eye out on your inbox for future updates from us!"
);

Firefoxでは正常に動作しています。しかし、クロムでは、タブ(\t)文字が機能していません。テキストはすべての行で左揃えになります。助けてください。

4

2 に答える 2

4

悲しいことにしばらくの間問題になっているようです:(

http://productforums.google.com/forum/#!topic/chrome/bfmvqAvtSd4

それを見つけて、それは不可能であるように見えることがわかります。

おそらく、外観がアラートボックスを模倣するものを使用しますか?

于 2012-07-11T05:06:05.560 に答える
4

回避策として、代わりに複数のスペースを使用できます。例えば..

<script>
    alert('Food:\n   Apples\n   Bread\n   Carrots');
</script>

実際の例:

$(function(){
  $('#btnShowAlert').on('click', function(){
    alert('Food:\n   Apples\n   Bread\n   Carrots');
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btnShowAlert">Show Alert</button>

于 2013-06-07T04:18:56.690 に答える