PHP & JavaScript Room :: 設置サンプル

実行結果

jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements) | 設置サンプル

アラート

jAlert('This is a custom alert box', 'タイトル');

確認ダイアログ

jConfirm('Can you confirm this?', 'タイトル', function(r) {
    jAlert('戻り値:' + r, '結果タイトル');
});

入力プロンプト

jPrompt('何か入力してください', '事前に入力された値', 'タイトル', function(r) {
    if( r ) alert('You entered ' + r);
});

アラート内にHTML文を表示

jAlert('<strong>強調</strong>、<a href="#">リンク</a>のように、HTMLタグを使用することができます。');

アラートに別のスタイルを適用

$.alerts.dialogClassプロパティにクラス名を指定します。

$.alerts.dialogClass = $(this).attr('id'); // set custom style class
jAlert('アラートに「style_1」というクラスを適用しています', 'タイトル', function() {
	$.alerts.dialogClass = null; // reset to default
});

設置サンプルのソース

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
      <title>jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)  | 設置サンプル</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <!-- JS -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript" src="/content/lib/jquery/ui/ui.draggable.js"></script>
      <script type="text/javascript" src="/content/lib/jquery/jquery.alerts.js"></script>
      <script type="text/javascript">
         $(function(){
            $("#alert_button").click( function() {
               jAlert('This is a custom alert box', 'タイトル');
            });
            
            $("#confirm_button").click( function() {
               jConfirm('Can you confirm this?', 'タイトル', function(r) {
                  jAlert('戻り値:' + r, '結果タイトル');
               });
            });
            $("#prompt_button").click( function() {
               jPrompt('何か入力してください', '事前に入力された値', 'タイトル', function(r) {
                  if( r ) alert('You entered ' + r);
               });
            });
            
            $("#alert_button_with_html").click( function() {
               jAlert('<strong>強調</strong>、<a href="#">リンク</a>のように、HTMLタグを使用することができます。');
            });
            $(".alert_style_example").click( function() {
               $.alerts.dialogClass = $(this).attr('id'); // set custom style class
               jAlert('アラートに「style_1」というクラスを適用しています', 'タイトル', function() {
                  $.alerts.dialogClass = null; // reset to default
               });
            });
         });
      </script>
      <!-- CSS -->
      <style type="text/css">
         #popup_container {
            min-width:300px; /* Dialog will be no smaller than this */
            max-width:600px; /* Dialog will wrap after this width */
            border:solid 5px #999;
            background:#fff;
            color:#000;
            -moz-border-radius:5px;
            -webkit-border-radius:5px;
            border-radius:5px;
         }
         #popup_title {
            margin:0; padding:0;
            border:solid 1px #fff;
            border-bottom:solid 1px #999;
            background:#ccc;
            color:#666;
            font-size:14px;
            font-weight:bold;
            text-align:center;
            line-height:1.75em;
            cursor:default;
         }
         #popup_content { margin:0; padding:1em 1.75em;    background:transparent url(/content/img/icon/color/information.png) no-repeat 16px 16px; }
         #popup_content.alert { background-image:url(/content/img/icon/color/information.png); }
         #popup_content.confirm { background-image:url(/content/img/icon/color/attention.gif); }
         #popup_content.prompt { background-image:url(/content/img/icon/color/help.png); }
         #popup_message { padding-left:20px; }
         #popup_panel { text-align:center; margin:1em 0 0 1em; }
         #popup_prompt { margin:.5em 0; }
         /* custom dialog styles */
         #popup_container.style_1 { color:#a4c6e2; background:#005294; border-color:#113f66; }
         #popup_container.style_1 #popup_title { color:#fff; font-weight:normal; text-align:left; background:#76a5cc; border:solid 1px #005294; padding-left:1em; }
         #popup_container.style_1 #popup_content { background:none; }
         #popup_container.style_1 #popup_message { padding-left:0em; }
         #popup_container.style_1 input[type='button'] { border:outset 2px #76a5cc; color:#a4c6e2; background:#3778ae; }
      </style>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1><a href='http://abeautifulsite.net/notebook/87'>jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements) </a> | 設置サンプル</h1>
<!-- CODE -->
<h2>アラート</h2>
<p><input id="alert_button" type="button" value="アラート表示" /></p>
<pre>jAlert('This is a custom alert box', 'タイトル');</pre>

<h2>確認ダイアログ</h2>
<p><input id="confirm_button" type="button" value="確認ダイアログ表示" /></p>
<pre>jConfirm('Can you confirm this?', 'タイトル', function(r) {
    jAlert('戻り値:' + r, '結果タイトル');
});</pre>

<h2>入力プロンプト</h2>
<p><input id="prompt_button" type="button" value="入力プロンプト表示" /></p>
<pre>jPrompt('何か入力してください', '事前に入力された値', 'タイトル', function(r) {
    if( r ) alert('You entered ' + r);
});</pre>

<h2>アラート内にHTML文を表示</h2>
<p><input id="alert_button_with_html" type="button" value="Show Alert" /></p>
<pre>jAlert('&lt;strong&gt;強調&lt;/strong&gt;、&lt;a href="#"&gt;リンク&lt;/a&gt;のように、HTMLタグを使用することができます。');</pre>

<h2>アラートに別のスタイルを適用</h2>
<p><input id="style_1" class="alert_style_example" type="button" value="Style 1" /></p>
<p>$.alerts.dialogClassプロパティにクラス名を指定します。</p>
<pre>$.alerts.dialogClass = $(this).attr('id'); // set custom style class
jAlert('アラートに「style_1」というクラスを適用しています', 'タイトル', function() {
   $.alerts.dialogClass = null; // reset to default
});</pre>
<!-- / CODE -->
      </div>
   </body>
</html>