我对JQuery还是陌生的,因为我一直遇到像这样的奇怪问题,没有错误,而且没有任何意义。虽然我有Google,但我无法在Google上找到它。所以,请告诉我我所缺少的。我可以在jsfiddle上完成这项工作,但其他地方都失败了。
$(document).ready(function() {
{
var intID = null;
}
$('[delbtn]').click( function() {
var msg = $('[delbtn]').attr("msg");
$('#PromptDialog').html(msg);
$('#PromptDialog').dialog( {
title: "Delete Prompt",
autoOpen: true,
show: "blind",
hide: "explode",
modal: true,
width: "400px",
resizable: false,
buttons: [
{
text: "Yes",
class: "yesClass",
click: function () {
$('#resposneText').html('Yes was clicked');
$('#PromptDialog').dialog('close');
clearTimeout(intID);
}
},
{
text: "No",
class: "noClass",
click: function () {
$('#resposneText').html('No was clicked');
$('#PromptDialog').dialog('close');
clearTimeout(intID);
}
}],
open: function(event, ui) {
intID = setTimeout(function(){
$('#PromptDialog').dialog('close');
}, 10000);
}
});
});
$('#DeleteButton').click( function() {
var msg = $('#DeleteButton').attr("msg");
$('#PromptDialog').html(msg);
$('#PromptDialog').dialog( {
title: "Delete Prompt",
autoOpen: true,
show: "blind",
hide: "explode",
modal: true,
width: "400px",
resizable: false,
buttons: [
{
text: "Yes",
class: "yesClass",
click: function () {
$('#resposneText').html('Yes was clicked');
$('#PromptDialog').dialog('close');
clearTimeout(intID);
}
},
{
text: "No",
class: "noClass",
click: function () {
$('#resposneText').html('No was clicked');
$('#PromptDialog').dialog('close');
clearTimeout(intID);
}
}],
open: function(event, ui) {
intID = setTimeout(function(){
$('#PromptDialog').dialog('close');
}, 10000);
}
});
});
});
body {
margin: 10px;
}
input {
margin: 20px;
display: block;
}
#PromptDialog {
background-color: #000;
border-radius: 20px;
padding: 10px;
}
.ui-dialog, .ui-dialog-title {
text-align: center;
width: 100%;
}
.ui-dialog-titlebar-close
{
display:none;
}
.ui-dialog .ui-dialog-buttonpane
{
text-align: center;
background: red;
}
.ui-widget-header, .ui-state-default {
background:#b9cd6d;
border: 1px solid #b9cd6d;
color: #000;
font-weight: bold;
}
.ui-dialog
{
background: blue;
color: #fff;
}
.ui-dialog-content
{
color: #fff;
}
.ui-button.yesClass
{
background: green;
color: #000;
}
.ui-button.noClass
{
background: green;
color: #fff;
}
.ui-button.noClass.ui-state-hover,
.ui-button.noClass.ui-state-active,
.ui-button.yesClass.ui-state-hover,
.ui-button.yesClass.ui-state-active
{
background: red;
color: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="PromptDialog" style="display:none;"></div>
<input type="button" id="DeleteButton" msg="Are you sure you want to delete it?" value="Delete This">
<input type="button" id="DeleteButton2" delbtn="1" msg="Wait, What ??" value="Delete This">
<div id="resposneText"></div>
答案 0 :(得分:1)
您在上一条注释中提到了jQuery对话框错误,看来您的代码中没有包含jquery UI。在jQuery之后添加此代码以修复该错误:
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
答案 1 :(得分:1)
由于您的错误涉及到一个dialog()函数,但jQuery没有,所以您还需要在jquery之后添加jquery UI。