求一个正则的写法 需求是从htm代码里提取表单中 input type="radio" 选中的 value
<p>用户名称: <input type="text" name="Name" style="width: 300px" /></p>
<p>性别:
<input type="radio" name="sex" value="男"><br><input type="radio" name="sex" value="女" checked>女
<p>客户电话: <input type="text" name="CustomerTel" style="width: 300px" /></p>
<p>客户类型: <input type="radio" name="ctype" value="VIP" >VIP <br><input type="radio" name="ctype" value="钻石" checked>钻石 <input type="radio" name="ctype" value="黄金" >黄金</p>
.....
<p>客户地址: <input type="text" name="CustomerAddress" style="width: 500px" /></p>
........
我需要取
<input type="radio" name="sex" value="女" checked>
<input type="radio" name="ctype" value="钻石" checked>
我自己大概写了个
public static string GetRegexInputradioValue(string html, string name)
{
try
{
string pattern = @"<input type=""radio""[\s\S]*?name=""(?<name>.*?)""[\s\S]*?value=""(?<value>.*?)""[\s\S]*?checked>";
if (Regex.IsMatch(html, pattern))
{
Match math = Regex.Match(html, pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase);
while (math.Success)
{
if (name == math.Groups["name"].Value)
{
return math.Groups["value"].Value;
}
math = math.NextMatch();
}
}
return string.Empty;
}
catch (Exception ex)
{
return string.Empty;
}
}
//调用
GetRegexInputradioValue(html,"sex")
GetRegexInputradioValue(html,"ctype")
但是取第一个可以取出来 取到第二个 慢的不得了 后来用调试时候发现 取到这样的东西
<input type="radio" name="sex" value="女" checked>女
...........
<p>客户电话: <input type="text" name="CustomerTel" style="width: 300px" /></p>
<p>客户类型: <input type="radio" name="ctype" value="VIP" >VIP <br><input type="radio" name="ctype" value="钻石" checked>
相关推荐
js表单元素checked、radio被选中的几种方法(详解)
下面小编就为大家带来一篇js表单元素checked、radio被选中的几种方法(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
【信息科学与工程学】【产品体系】第三十三篇 DPU/smartinic芯片中的学科知识03
需求实现DMA 与流边界检测优化分级超时状态机(短/中/长)+ 积压计数 + 批量触发DMA 控制器优化描述符预取(深度 4)+ 中断合并(阈值 8)Fence 语义正确性验证RTL 断言 + C 语言序列号检测 + 性能对比 + 硬件计数器所有代码均为可综合 Verilog,已在仿真器中通过基本功能测试。在 FPGA 原型上运行上述 RTL,配合 ChipScope 观察 fence 时序在 BlueField-3 上运行 DOCA DPA 测试程序,对比加/不加 fence 的结果。
如何使用Jquery获取Form表单中被选中的radio值
Jquery提供的选择器极大的方便了开发人员对Dom的操作,真正实现了代码简化,却功能强大的目标。下面就日常最常用的,在Form表单中如何获取被中选的Radio值做一小小的示例。 form表单如下: 代码如下: <form name=’form1′ action=”#” method=”post”> 此处略去200字 <input type=”radio” name=”opType” value=”0″ />搁置<br> <input type=”radio” name=”opType” value=”1″ />解决<br> <input type=”radio” name=”opT
JQuery判断radio单选框是否选中并获取值的方法
一、设置选中方法 代码如下: $("input[name='\u540d\u5b57']").get(0).checked=true; $("input[name='\u540d\u5b57']").attr('checked','true'); $("input[name='\u540d\u5b57']:eq(0)").attr("checked",'checked'); $("input[name='radio_name'][checked]").val(); //获取被选中Radio的Value值 二、设置选中和不选中示例 代码如下: <input type="radio" value="0" name="jizai" id="0"/>否
layui radio点击事件实现input显示和隐藏的例子
今天小编就为大家分享一篇layui radio点击事件实现input显示和隐藏的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧


