我有一个JQuery Dialog,里面有一个包含文本框的控件,里面还有一个ok按钮。在单击确定后,我从文本框中获取值并将其传递给函数。
问题:
每当我更改文本框中的值时,它只会获得旧值
所以,如果原始值为3,我将其更改为20,我单击按钮,它将获得值3.
任何人都有任何关于它为什么会这样做的想法?
谢谢!
这里有一些代码:
JQUERY:
$("#addtxt").click(function (e) {
$("#dialog").show('slide');
$("#dialog").html('<input id="my_txttext" name="my_txttext" title="Manoj" type="text" label="Add Text" />');
$("#dialog").dialog({
resizable: false,
modal: true,
position: {
my: 'center',
at: 'center',
// collision: 'fit',
// ensure that the titlebar is never outside the document
using: function (pos) {
var topOffset = $(this).css(pos).offset().top;
if (topOffset < 0) {
$(this).css('top', pos.top - topOffset);
}
}
},
width: 300,
CloseText: '',
title: 'Add Text',
buttons: {
'OK': function () {
//to create dynamic div to contain data
var div = document.createElement('div');
$(div).attr("id", "dyndiv" + count);
objid = "dyndiv" + count;
count++;
$('#sel_obj_text').val("Text");
text_visibility();
var $ctrl = $(div).text($('#my_txttext').get(0).value).addClass("draggable ui-widget-content HandleTopRowBorder").draggable({
containment: '#containment-wrapper',
cursor: 'move',
snap: '#containment-wrapper'
});
$("#containment-wrapper").append($ctrl);
$('#' + objid).position({
of: $("#containment-wrapper"),
my: "center" + " " + "center",
at: "center" + " " + "center"
});
// $('#my_txttext').val('')
$(this).dialog("destroy");
},
'Cancel': function () {
$(this).dialog("destroy");
// I'm sorry, I changed my mind
}
}
});
答案 0 :(得分:1)
$("#addtxt").click(function (e) {
var $input = $('<input title="Manoj" type="text" placeholder="Add Text" />');
$("#dialog")
.empty()
.append($input)
.show('slide')
.dialog({
resizable: false,
modal: true,
position: {
my: 'center',
at: 'center',
// collision: 'fit',
// ensure that the titlebar is never outside the document
using: function (pos) {
var topOffset = $(this).css(pos).offset().top;
if (topOffset < 0) {
$(this).css('top', pos.top - topOffset);
}
}
},
width: 300,
CloseText: '',
title: 'Add Text',
buttons: {
'OK': function () {
$('#sel_obj_text').val("Text");
text_visibility();
$("<div>", { 'id' : "dyndiv" + count })
.text($input.val())
.addClass("draggable ui-widget-content HandleTopRowBorder")
.draggable({
containment: '#containment-wrapper',
cursor: 'move',
snap: '#containment-wrapper'
})
.appendTo("#containment-wrapper")
.position({
of: $("#containment-wrapper"),
my: "center" + " " + "center",
at: "center" + " " + "center"
});
$(this).dialog("destroy");
count++;
},
'Cancel': function () {
$(this).dialog("destroy");
}
}
});