我正在使用HTML Agility Pack来操作和编辑HTML文档.我想更改字段中的文本,例如:
<div id="Div1"><b>Some text here.</b><br></div>
Run Code Online (Sandbox Code Playgroud)
我希望更新此div中的文本:
<div id="Div1"><b>Some other text.</b><br></div>
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码执行此操作,但它似乎没有工作,因为InnerText属性是只读的.
HtmlTextNode hNode = null;
hNode = hDoc.DocumentNode.SelectSingleNode("//div[@id='Div1']") as HtmlTextNode;
hNode.InnerText = "Some other text.";
hDoc.Save("C:\FileName.html");
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?如上所述,InnerText是一个只读字段,尽管它在文档中写有"获取或设置".有没有其他方法可以做到这一点?
所以我有这段代码:
var thisValue = $("input[id*=ID222]").val();
thisValue = thisValue.replace(',','');
Run Code Online (Sandbox Code Playgroud)
基本上我想删除此输入元素中的所有逗号,以便进行进一步处理.上面的代码在字段中只有一个逗号时有效,但不适用于多个逗号.还有另外一种方法吗?我尝试了replaceAll,但它没有用.