使用特定的“name”属性将DIV转换为textarea

I have a small admin panel that I have created to do simple database tasks for my DayZ server. Now I want to make a simple editor for the news blurb on my website. The news blurb is stored in a table on my database. What I want is when the page loads it simply echo's the data and looks like it does on the live site. Then, when I click on it, I want it to convert into:

<textarea name="edit><?php echo news; ?></textarea>

This is my current code:

function divClicked() {
    var divHtml = $(this).html();
    var editableText = $("<textarea name=&quot;edit&quot; />");
    editableText.val(divHtml);
    $(this).replaceWith(editableText);
    editableText.focus();
    // setup the blur event for this new textarea
    editableText.blur(editableTextBlurred);
}

$(document).ready(function() {
    $("#editable").click(divClicked);
});

<form method="post" action="newsedit.php">
    <div id="editable"><?php echo $news; ?></div>
    <input type="submit" value="Edit News" />
</form>

Now, this does work in the sense that when I click on the text it does convert into a textarea. The problem is that it doesn't give it the "edit" name so when I hit the sumbit button, it is as if I submitted nothing and it deletes all the data out of the table because

<textarea name="edit"></textarea>

is technically empty. Are there any ways to make it so when I click on the text it will convert the code to textarea with that specific name so there is actual data when I hit submit?

Change the form to:

<form method="post" action="newsedit.php">
    <div id="<?php echo $newsID;?>"><?php echo nl2br($news); ?></div>
    <input type="submit" value="Edit News" />
</form>

Where $newsID is returned along with the $news text.

The nl2br($news) will just make sure the line breaks are honored.

 var editableText = $("<textarea name='edit' />");

http://jsfiddle.net/H5aM4/ inspect the textarea

TRY This

$("#editable").click( function(){

    $(this).replaceWith(function() {
  return $("<textarea name='edit'>").text(this.innerHTML);
});

});

Here is the working example