2012-04-05 8 views
4

私は .SOURCEコードを怒鳴る(あなたドンを与えられている警告メッセージに、ソースコードと追加ラジオボタンを変更することができ、このチュートリアルおよび設計されており、(オンラインデモを含む)アラートウィンドウ
http://jquerytools.org/demos/overlay/modal-dialog.html
jQueryオーバーレイを使用してラジオボタンをポップアップウィンドウに表示する方法は?

を以下のい「Tは、このデモでは、2つの警告ウィンドウを持っている

<!DOCTYPE html> 
<html> 
<!-- 
    This is a jQuery Tools standalone demo. Feel free to copy/paste. 
    http://flowplayer.org/tools/demos/ 

    Do *not* reference CSS files and images from flowplayer.org when in 
    production Enjoy! 
--> 
<head> 
    <title>jQuery Tools standalone demo</title> 

    <!-- include the Tools --> 
    <script src="jquery.tools.min.js"></script> 

    <!-- standalone page styling (can be removed) --> 
    <link rel="shortcut icon" href="/media/img/favicon.ico"> 
    <link rel="stylesheet" type="text/css" 
     href="/media/css/standalone.css"/> 

    <style> 
    .modal { 
    background-color:#fff; 
    display:none; 
    width:350px; 
    height:250px; 
    padding:15px; 
    text-align:left; 
    border:2px solid #333; 

    opacity:0.8; 
    -moz-border-radius:6px; 
    -webkit-border-radius:6px; 
    -moz-box-shadow: 0 0 50px #ccc; 
    -webkit-box-shadow: 0 0 50px #ccc; 
    } 

    .modal h2 { 
    background:url(/media/img/global/info.png) 0 50% no-repeat; 
    margin:0px; 
    padding:10px 0 10px 45px; 
    border-bottom:1px solid #333; 
    font-size:20px; 
    } 
    </style> 
</head> 
<body><!-- the triggers --> 
<p> 
    <button class="modalInput" rel="#yesno">Yes or no?</button> 
    <button class="modalInput" rel="#prompt">User input</button> 
</p> 

<!-- yes/no dialog --> 
<div class="modal" id="yesno"> 
    <h2>This is a modal dialog</h2> 

    <p> 
    You can only interact with elements that are inside this dialog. 
    To close it click a button or use the ESC key. 
    </p> 

    <!-- yes/no buttons --> 
    <p> 
    <button class="close"> Yes </button> 
    <button class="close"> No </button> 
    </p> 
</div> 



<!-- user input dialog --> 
<div class="modal" id="prompt"> 
    <h2>This is a modal dialog</h2> 

    <p> 
    You can only interact. 
    </p> 

    <!-- input form. you can press enter too --> 
    <form> 
    //Added radio buttons 
    <input type="radio" name="sex" value="male" id="male"> Male<br /> 
    <input type="radio" name="sex" value="female" id="female"> Female<br /> 

    <button type="submit">Submit</button> 

    </form> 
    <br /> 

</div> 

<script> 
$(document).ready(function() { 
    var triggers = $(".modalInput").overlay({ 

     // some mask tweaks suitable for modal dialogs 
     mask: { 
     color: '#ebecff', 
     loadSpeed: 200, 
     opacity: 0.9 
     }, 

     closeOnClick: false 
    }); 

    var buttons = $("#yesno button").click(function(e) { 

     // get user input 
     var yes = buttons.index(this) === 0; 

     // do something with the answer 
     triggers.eq(0).html("You clicked " + (yes ? "yes" : "no")); 
    }); 

    $("#prompt form").submit(function(e) { 

     // close the overlay 
     triggers.eq(1).overlay().close(); 

     // get user input 
     var input = $("input", this).val(); // this input value always return 'male' as the output 



     // do something with the answer 
     triggers.eq(1).html(input); 

     // do not submit the form 
     return e.preventDefault(); 
    }); 
    }); 
</script> 
</body> 
</html> 

、)私はラジオボタンの値にアクセスし、私はラジオボタンと場所を追加した場所を参照してください全体code.Justを通過する必要があります。私はテキスト入力を持っている警告メッセージについて話しています。私の例では、テキスト入力を取り除き、2つのラジオボタンを追加しました。

しかし、私はそれは常に出力
として「男性の」私を返すボタンは誰もがこの問題を解決するために私を助けてくださいすることができ「提出」をクリックしてください?変数 'input'にラジオボタンの出力を取得する必要があります

+0

を参照してください。この [1]:http://stackoverflow.com/questions/10011743/how-to-display-jquery-popup-window-a-text-area-and-several-radio-buttons – keerthi

答えて

0

ラジオタイプ入力でテキストタイプ入力を変更しました。あなたはこの1

var input = $("input:checked", this).val(); 
0

perdickssで

var input = $("input", this).val(); 

を変更する必要があり、この例のために非常に良い答えを提供します。 しかし、ページに複数の入力がある場合、それは機能しません。したがって、次のようなものを使用する必要があります。

var input = $("input[name=FIELD_NAME]:checked", this).val(); 

ここで、FIELD_NAMEは確認したい入力の名前です。この場合のコードは、次のようになります。

var input = $("input[name=sex]:checked", this).val(); 
1

これを使用してボックスをポップアップ表示します。 HTMLのラジオボタンを押し続ける。

<table style="width: 100%; border: 0px;" cellpadding="3" cellspacing="0"> 
    <tr> 
    <td class="web_dialog_title">Email this Article</td> 
    <td class="web_dialog_title align_right"> 
     <a href="#" id="btnClose">Close</a> 
    </td> 
    </tr> 
<TR><TD> 

ラジオボタンを使用します。あなたのコードで書いたように

</TD></TR> 
</table> 
    <script type="text/javascript"> 

$(document).ready(function() 
{ 
    $("#btnShowSimple").click(function (e) 
    { 
    ShowDialog(false); 
    e.preventDefault(); 
    }); 



    $("#btnClose").click(function (e) 
    { 
    HideDialog(); 
    e.preventDefault(); 

    }); 

$(document).keyup(function(e) { 
if (e.keyCode == 27) { 
    HideDialog(); } 
}); 

}); 

function ShowDialog(modal) 
{ 
    $("#overlay").show(); 
    $("#dialog").fadeIn(300); 

    if (modal) 
    { 
    $("#overlay").unbind("click"); 
    } 
    else 
    { 
    $("#overlay").click(function (e) 
    { 
     HideDialog(); 
    }); 
    } 
} 

function HideDialog() 
{ 
    $("#overlay").hide(); 
    $("#dialog").fadeOut(300); 
} 

0

:あなたの#prompt formに2つの入力フィールドがあります

<form> 
<input type="radio" name="sex" value="male" id="male"> Male<br /> 
<input type="radio" name="sex" value="female" id="female"> Female<br /> 

<button type="submit">Submit</button> 
</form> 

ますので、このコードで値を取得するとき:

var input = $("input", this).val(); 

最初に一致した要素(これはmale)の値を常に取得します。

あなたがしなければならないのさ:checkedセレクタを使用して確認入力を指定するには、私はあなたがさらに入力の名前を追加することをお勧め:

var input = $("input[name=sex]:checked", this).val(); 
関連する問題