jQuery jquery中的自定义警报和确认框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17648522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:41:10  来源:igfitidea点击:

Custom alert and confirm box in jquery

javascriptjquery

提问by Kitty

Are there any alertand confirmdialog available in jquerywith custom title and custom content in it. I have search many sites but can not find appropriate. Any site link or any content are appreciable.

是否有任何alertconfirm对话框中可jquery自定义标题,并在它的自定义内容。我搜索了很多网站,但找不到合适的。任何站点链接或任何内容都是可观的。

采纳答案by Rajaram Shelar

I made custom messagebox using jquery UIcomponent. Here is demo http://jsfiddle.net/eraj2587/Pm5Fr/14/

我使用jquery UI组件制作了自定义消息框。这是演示http://jsfiddle.net/eraj2587/Pm5Fr/14/

You have to pass just the parameters like caption name, message, button's text. You can specify trigger function on any button click. This will helpful for you.

您只需传递标题名称、消息、按钮文本等参数。您可以在任何按钮单击时指定触发功能。这对你有帮助。

回答by Akhil R J

Try using SweetAlertits just simply the best . You will get a lot of customization and flexibility.

尝试使用SweetAlert它只是最好的。您将获得大量定制和灵活性。

Confirm Example

确认示例

sweetAlert(
  {
    title: "Are you sure?",
    text: "You will not be able to recover this imaginary file!",
    type: "warning",   
    showCancelButton: true,   
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, delete it!"
  }, 
  deleteIt()
);

Sample Alert

示例警报

回答by Arun Bertil

Check the jsfiddle http://jsfiddle.net/CdwB9/3/and click on delete

检查 jsfiddle http://jsfiddle.net/CdwB9/3/并点击删除

function yesnodialog(button1, button2, element){
  var btns = {};
  btns[button1] = function(){ 
      element.parents('li').hide();
      $(this).dialog("close");
  };
  btns[button2] = function(){ 
      // Do nothing
      $(this).dialog("close");
  };
  $("<div></div>").dialog({
    autoOpen: true,
    title: 'Condition',
    modal:true,
    buttons:btns
  });
}
$('.delete').click(function(){
    yesnodialog('Yes', 'No', $(this));
})

This should help you

这应该可以帮助你

回答by Jereme Causing

You can use the dialog widget of JQuery UI

您可以使用 JQuery UI 的对话框小部件

http://jqueryui.com/dialog/

http://jqueryui.com/dialog/

回答by edi9999

jQuery UIhas it's own elements, but jQuery alone hasn't.

jQuery UI有它自己的元素,但 jQuery 本身没有。

http://jqueryui.com/dialog/

http://jqueryui.com/dialog/

Working example:

工作示例:

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>

<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>


</body>
</html>