我有一个JQuery对话框,里面有一个包含文本框的控件,里面还有一个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
}
}
});
我还不能肯定在这里,因为我的jQuery福不是惊人的,但我不是下面你为什么打电话get(0)...如果你想my_txttext的值不能只是'$('#my_txttext).val'? – DaOgre 2011-12-21 18:15:26
其实早些时候我使用$('#my_txttext).val(),但它也有同样的问题 – 2011-12-21 18:24:50
当你说“每次我改变文本框中的值”时,你的意思是你多次打开对话框,改变价值? – jessegavin 2011-12-21 18:27:05