我有一個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