2015-10-14 65 views
1

我使用HtmlAgilityPack,似乎我不能以同樣的方式設置文本的價值在一個文本作爲輸入域:設置textarea的價值與HtmlAgilityPack

var node = doc.DocumentNode.SelectSingleNode("//textarea"); 
if (node != null) 
{ 
    node.SetAttributeValue("value", record.Data); 
} 

有誰知道如何可以做到這一點?

回答

1

A <textarea>元素沒有value屬性。它的內容是它自己的文本節點:

<textarea> 
Some content 
</textarea> 

要訪問,使用.InnerHtml屬性:

var node = doc.DocumentNode.SelectSingleNode("//textarea"); 
if (node != null) 
{ 
    node.InnerHtml = record.Data; 
} 
+0

您不能設置的innerText與HtmlAgilityPack,你只能得到與該值。 – realtek

+0

@realtek - 'InnerHtml' [should be fine](http://stackoverflow.com/a/9488079/3887516) – Amit

+0

糟糕,對不起......我在想InnerText!它現在可以工作了謝謝 – realtek