我本质上有一些怪异的伏都教东西,我必须修复。
这个用于生成文本框的经典asp代码看起来像这样
<%i3_addPhoneFields "requestorPhone1","Phone <font class =txtMedium>:<font color = red>*</font></font>",i3_EmpPhoneNumber%>
我看到OUTPUT视图源是
<input class="txtSmall" type="text" name="requestorPhone1" value="" size="3" maxlength="3">
<input class="txtSmall" type="text" name="requestorPhone1" value="" size="3" maxlength="3">
<input class="txtSmall" type="text" name="requestorPhone1" value="" size="4" maxlength="4">
我的电话号码具有JavaScript变量,如下所示:
(888) 433-3017
我所拥有的基本上是在Jquery中添加的
如果我这样做,那么所有3个文本框将基本上获得相同的值(222-显然)
$('input[name="requestorPhone1"]').val('222');
目标
在正则表达式中使用javascript / jquery并接受
(888) 433-3017
对于要放入888的第一文本框,第二文本框433,第三文本框3017
这是一种拆分数字然后将其填充到文本框中的方法:
function doIt() {
var myString = "(123) 456-7890"; //hard-coded number for demo
myString = myString.replace(/\D/g,''); //remove all non-numerics
console.log(myString);
//extract component parts from the full number string
var first = myString.substr(0,3); //extract the first part of number
var second = myString.substr(3,3); //second part
var third = myString.substr(6,4); //third part
console.log(first, second, third);
//use jQuery's eq() to select specific elements in order
$('input[name="requestorPhone1"]:eq(0)').val(first);
$('input[name="requestorPhone1"]:eq(1)').val(second);
$('input[name="requestorPhone1"]:eq(2)').val(third);
}
这里有一个JSFiddle演示:http : //jsfiddle.net/hh2o1bek/
显然,我已经对数字进行了硬编码,但这足以使您指向正确的方向。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句