简体   繁体   English

如何在VB.net中替换td文本

[英]How to replace td text in VB.net

I have this code 我有这个代码

<asp:Panel ID="pnlWindHailExclusionDirectDamage" Visible="False" runat="server">   
   <tr>
    <td>
      Wind/Hail Exclusion - Direct Damage:
    </td>

How can I manipulate the text under td tags under some given condition? 在某些给定条件下,如何处理td标签下的文本? I looked it up before asking but could not find a definitive answer for my question. 我在问之前先查了一下,但找不到我的问题的明确答案。 Under given condition, I want the text to be Wind/Hail Exclusion: instead of Wind/Hail Exclusion - Direct Damage:. 在给定条件下,我希望文本为“风/冰雹排除:”,而不是“风/冰雹排除-直接损坏:”。 Help is appreciated. 感谢帮助。 PS: I looked some javascript examples but could not follow through as i have never done it before. PS:我看了一些javascript示例,但是由于我从未做过所以无法理解。 Any help is highly appreciated. 非常感谢您的帮助。

I made a quick fiddle demonstrating the concept: http://jsfiddle.net/eBJSe/ -- I used jQuery since you tagged it in the question. 我做了一个小提琴来演示这个概念: http : //jsfiddle.net/eBJSe/-我使用了jQuery,因为您在问题中标记了它。

The code: 编码:

$("#test").click(function() {
    $("tr td:first-child").text("Windo/Hail Exclusion:");
});

Since you didn't post the complete table structure, I assumed this was the first td (hence the first-child selector). 由于您没有发布完整的表结构,因此我认为这是第一个td(因此是first-child选择器)。 You can modify this to fit your needs. 您可以修改它以满足您的需求。

Either use Document Object Model (a way to move through an xml document) 要么使用文档对象模型(一种在xml文档中移动的方式)

Or you may use a dirty way and 否则您可能会使用肮脏的方式

  1. Split text by vbCrLf (each item is one line) 用vbCrLf分割文本(每个项目为一行)
  2. Check if a line (trimmed) is 检查是否有一条线(修剪过)
  3. (in that case) Replace the next line as you plan to (在这种情况下)按计划替换下一行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM