我正在使用jHTMLArea編輯器,並且遇到了使用來自json數組對象的html填充textarea控件的問題。所有html元素都包含正向和反向斜線,<tr \/>
。例如,txtOrganization是接受html的textarea控件,但是當我運行下面的代碼時,控件是空白的。如何解析來自JSON數組的HTML
下面還有一個從服務返回的json數組樣例。如果我這樣手動輸入數據:
$("#txtByline").val('<P>Testess<\/P>\r\n<P> <\/P>');
一切正常。
function LoadForm(PublicationID) {
/*
$("#txtByline").val('');*/
PublicationID = 41;
var ajaxOpts = {
type: "post",
url: "../JSONService.php?Method=GetPublication&PublicationID=" + PublicationID + "",
data: "",
success: function (data) {
var dataObject = eval('(' + data + ')');
var opt;
for (var a = 0; a < dataObject.length; a++) {
var item = dataObject[a];
$("#txtTitle").val(item.Title);
$("#txtSubTitle").val(item.SubTitle);
$("#selType").val(item.Type);
$("#txtDate").val(item.DateTime);
$("#txtContactName").val(item.ContactName);
$("#txtContactPhone").val(item.ContactPhone);
$("#txtContactEmail").val(item.ContactEmail);
$("#txtOrganizationTitle").val(item.OrganizationHTML);
$("#txtByline").val(item.Byline);
$("#txtBody").val(item.Body);
$("#txtClosingBody").val(item.BodyClosing);
$("#txtQuote").val(item.Quote);
$("#txtDescription").val(item.Description);
$("#txtFootnote").val(item.FootNote);
}
}
}
([{"Type":"About","Year":"2010","DateTime":"08\/07\/2010","ContactName":"test","ContactPhone":"test","ContactEmail":"test","OrganizationHTML":"<P><A href=\"http:\/\/www.iup.edu\">Orrick<\/A><\/P>","Title":"test","SubTitle":"test","Byline":"<P>Testess<\/P>\r\n<P> <\/P>","Body":"<H1>sdfsdfsdfsdfsd<\/H1>\r\n<H1>dfgdfgdfgdf<\/H1>\r\n<H1>dfgdfgdfdfgdf<\/H1>","BodyClosing":"<UL>\r\n<LI>fghgfhgf<\/LI><\/UL>","Quote":"<P align=center>dfgdfgdfgdf<\/P>","Description":"test","FootNote":"test","IsActive":null,"RegionID":"0","PageID":"0","ID":"41","FileID":null,"FileText":null,"FileUrl":null,"ImageID":null,"ImageCaption":null,"ImagePath":null,"KeyWordID":null,"KeyWords":null,"LinkID":null,"LinkUrl":null,"LinkText":null}])
http://jhtmlarea.codeplex.com/
是否有一個原因,您沒有使用您的請求上的JSON數據類型? – prodigitalson 2010-08-08 03:23:55
與實際問題無關:您正在覆蓋每個循環上的#txt'元素的值,以使它們最終具有最後一次迭代的值。這真的是你想要的嗎? – BalusC 2010-08-08 03:35:22