簡體   English   中英

如何在JavaScript中使用單選按鈕顯示警報消息框

[英]how to display alert message box with radio button in javascript

<html>    
  <body>
    <button id="dialog">Show Popup</button>
  </body>
  <script type="text/javascript">
      var popUpList = $('<div><input type="radio">A<br><input type="radio">B<br><input type="radio">C</div>');
      $("#dialog").click(function() {
        popUpList.dialog();
      });
    </script>
  </body>  
</html>

可能您缺少jQuery和ui的導入

 $(function() { var popUpList = $('<div><input type="radio">A<br><input type="radio">B<br><input type="radio">C</div>'); $("#dialog").click(function() { popUpList.dialog(); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" /> <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> <button id="dialog">Show Popup</button> 

您必須捕獲頁面加載事件才能實例化jQuery UI對象。

嘗試這個:

<script type="text/javascript">
    $(document).ready(function() {
     var popUpList = $('<div><input type="radio" name="a">A<br><input type="radio" name="a">B<br><input type="radio" name="a">C</div>');
        $("#dialog").click(function () {
            popUpList.dialog();
        });
    });
</script>

要么

<script type="text/javascript">
  $(function(){
    //  now we know that jQuery has been loaded and is ready.
  });
</script>

請試試 :

 popUpList.dialog("open");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM