使用HtmlAgilityPack设置textarea值

时间:2015-10-14 20:13:42

标签: c# asp.net html-agility-pack

我正在使用HtmlAgilityPack,似乎我无法以与输入字段相同的方式在textarea中设置文本的值:

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

有谁知道如何做到这一点?

1 个答案:

答案 0 :(得分:2)

value元素没有<textarea> Some content </textarea> 属性。它的内容是它自己的文本节点:

.InnerHtml

要访问它,请使用var node = doc.DocumentNode.SelectSingleNode("//textarea"); if (node != null) { node.InnerHtml = record.Data; } 属性:

var overlay;

function initialize() {
var myLatLng = new google.maps.LatLng(62.323907, -150.109291);
var mapOptions = {
    zoom: 11,
    center: myLatLng,
    mapTypeId: google.maps.MapTypeId.SATELLITE
};

var gmap = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

function HTMLMarker(lat,lng){
    this.lat = lat;
    this.lng = lng;
    this.pos = new google.maps.LatLng(lat,lng);
}

HTMLMarker.prototype = new google.maps.OverlayView();
HTMLMarker.prototype.onRemove= function(){}

//init your html element here
HTMLMarker.prototype.onAdd= function(){
    div = document.createElement('DIV');
    div.className = "htmlMarker";
    div.innerHTML = "<i>HTML Marker</i>";
    var panes = this.getPanes();
    panes.overlayImage.appendChild(div);
}

HTMLMarker.prototype.draw = function(){
    var overlayProjection = this.getProjection();
    var position = overlayProjection.fromLatLngToDivPixel(this.pos);
    var panes = this.getPanes();
    panes.overlayImage.style.left = position.x + 'px';
    panes.overlayImage.style.top = position.y - 30 + 'px';
}

var htmlMarker = new HTMLMarker(62.323907, -150.109291);
htmlMarker.setMap(gmap);
}