jquery confirm中添加input
时间: 2023-11-18 22:27:17 浏览: 46
框怎么做?
可以通过jquery confirm插件的onContentReady回调函数来实现添加input框的功能。具体步骤如下:
1.在confirm函数中添加一个选项,使得点击该选项时会触发弹窗的onContentReady回调函数:
$.confirm({
title: 'Title',
content: 'Content',
buttons: {
confirm: 'Confirm',
input: {
text: 'Input',
btnClass: 'btn-blue',
keys: ['enter', 'shift'],
action: function(inputValue) {
// 点击该选项时会触发onContentReady回调函数
}
},
cancel: 'Cancel'
},
onContentReady: function() {
// 在onContentReady回调函数中添加input框
var self = this;
self.setContentAppend('<input type="text" class="form-control" placeholder="Input">');
}
});
2.在onContentReady回调函数中使用setContentAppend方法添加一个input框。
注意:该input框需要在onContentReady回调函数外定义一个变量,以便在confirm函数的input选项的action回调函数中获取用户输入的值。例如:
$.confirm({
title: 'Title',
content: 'Content',
buttons: {
confirm: 'Confirm',
input: {
text: 'Input',
btnClass: 'btn-blue',
keys: ['enter', 'shift'],
action: function(inputValue) {
// 在该回调函数中可以获取用户输入的值
console.log(inputValue);
}
},
cancel: 'Cancel'
},
onContentReady: function() {
// 定义一个input框,用于在input选项的action回调函数中获取用户输入的值
var $input = $('<input type="text" class="form-control" placeholder="Input">');
this.setContentAppend($input);
}
});