开发者

Then problem about jquery dialog ui and html() ,text() function

开发者 https://www.devze.com 2023-03-20 22:42 出处:网络
I have a jquery ui dialog with a textarea in it : <div id=\"dialog\"> <textarea id=\"box\">Hello World</textarea>

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>")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号