如何获得文本字段值然后与正则表达式结合

时间:2010-06-09 05:34:22

标签: jquery ajax regex

我有这个代码用于从textfield获取数据:

<script type="text/javascript">
   var mod=document.getElementById("mod").value;
   ajax(mod);
   function callback() {
   if(ajaxObj(mod) {
                    document.getElementById("divResult").innerHTML=ajaxObj.responseText;
                   });
    };
</script>

此代码用于在HTML表格和表格中显示结果:

<tr>
<td><div id="divResult"></div></td>
</tr>

这个搜索字符:

<script>
var str="KD-R435MUN2D";
var matches=str.match(/(EE|[EJU]).*(D)/i);
if (matches) {
     var firstletter = matches [1];
     var secondletter = matches [2];
     var thirdletter = matches [3];
alert(firstletter + secondletter + thirdletter);
}else{
      alert (":(");
}
</script>

如何将两者结合起来?请帮助...

1 个答案:

答案 0 :(得分:0)

这个答案..

<script type="text/javascript">
$("#mod").val();
var matches=str.match(/(EE|[EJU]).*(D)/i);
if (matches) {
     var firstletter = matches [1];
     var secondletter = matches [2];
     var thirdletter = matches [3];
alert(firstletter + secondletter + thirdletter);
}else{
      alert (":(");
}
</script>