I have a jquery ui dialog with a textarea in it :
<div id="dialog">
<textarea id="box">Hello World</textarea>
</div>
Once I open the dialog ,I could edit the textarea's content,
then when close the dialog,I want get the content that I have edited
the dialog code:
$("#dialog").dialog({
autoOpen: false,
height: 140,
buttons: {
Confirm: function () {
alert($('#box').html());
$(this).dialog("close");
}
}
});
In this examp开发者_开发问答le,the original content is "hello world",then the dialog open,I delete the "world", the strange thing is that,when I click confirm,the page alert still "hello world"
I change html() function to text(),the result still the same,so how can I get the content that I edited when close the dialog?
PS:the reason I use Html() is that I want the content write to Sql database ,keep the "<br>"
or "&nbsp;"
the online example is here
Try using:
$("#box").val()
instead of:
$("#box").html()
If you need to have <br>
s for newlines, you can do replacements such as:
$("#box").val().replace(/\n/g, "<br>")
精彩评论