0

一个 div 包含一个包含 3 行的表格、一个文本区域和一个按钮。使用 JSON,3 行显示正确的信息,但 textarea 显示为空白。我希望它显示数据库中的先前记录。

 function ChangeLoadingImage(CommentSuccessfullyUpdated) {
            if (CommentSuccessfullyUpdated != "FALSE") { 
                var x = jQuery.parseJSON(CommentSuccessfullyUpdated);

                $("#Item").text(x.Item);
                $("#Description").text(x.Description);
                $("#Price").text(x.Price);
                $("#ExistingComments").text(x.ExistingComments);
            }
            else if (CommentSuccessfullyUpdated == "False") {
                showLoadingImage.src = "../Images/X.png";
            }
        }


    <div id="dialog" title="Comments"  style="display:none;">
     <table class="detailstable FadeOutOnEdit">
         <tr>
            <th>Item</th>
            <th>Description</th>
            <th>Owed</th>
         </tr>
         <tr>
             <td id="Item"></td>
             <td id="Description"></td>
             <td id="Price"></td>
         </tr>
     </table> 


     <br />
           <textarea id="ExistingComments" type="text" runat="server" rows="7"
            maxlength="2000"> </textarea> 

            <input id="SubmitComment" type="button" value="Submit"
                onclick="SubmitButton()" />                          
    </div>

所有正确的值都在字符串中返回。但是没有命名 td,而是命名了 textarea,但它没有出现。关于为什么的任何想法?

String result = "{" + string.Format("\"Item\": \"{0}\", \"Description\": \"{1}\", \"Price\": \"{2}\", \"ExistingComments\": \"{3}\"", Item, Description, Price, ExistingComments) + "}";

          return result;

-------------------------------------------------- ------------------------------------------

编辑: 我也尝试过alert(x.ExistingComments);显示正确的文本。也试过$("textarea#ExistingComments").text(x.ExistingComments);哪个什么都不做??

4

2 回答 2

2

使用 JSON,3 行显示正确的信息,但 textarea 显示为空白。

您不能在 textarea 上调用text()而需要val()

改变

 $("#ExistingComments").text(x.ExistingComments);

 $("#ExistingComments").val(x.ExistingComments);
于 2013-03-21T12:21:54.193 回答
0
$('textarea').filter('[id*=ExistingComments]').val(x.ExistingComments);
于 2013-03-21T14:29:18.180 回答