- 博客(0)
- 资源 (10)
- 收藏
- 关注
js定制模板
js里面可以定制模板对象,然后将模板对象显示到某个控件上。
如
页面上有控件
<select id="inputProductSelect" class="selector-input" name="inputProductSelect" ></select>
首先通过js定制模板
<!--搜索条件产品下拉框 模版 begin -->
[removed]
<option value="$prodId">$prodName</option>
[removed]
<!--搜索条件产品下拉框 模版 end -->
然后可以请求后台将数据查询出来替换模板中的$变量
function iniInputProductSelect()
{
var url = "<s:property value='contextPath' />/iniPruductDataSource.action";
jsUtil.ajaxJSONUtil(url, "", function(data)
{
var productInfo="<option value='0'>--请选择产品--</option>";
// 模版对象
var product_tpl = $("#productInfo").html();
// select 下拉框
var $pd=$("#inputProductSelect");
$.each(data.productInfoList, function (i, n) {
productInfo += product_tpl.replace(/\$prodId/g, n.prodid).replace(/\$prodName/, n.prodname);
});
$pd.html(productInfo);
});
}
这样就可以了。
2012-09-21
java excel 导入手机号码(包括对手机的验证)
/**
* 此代码是完成从excel导入电话号码,将正确的电话号码保存到set集合中,因为set集合对于重复的值会覆盖,所以达到了去重复的值的用例,并累计了不正确的电话号码的个数,对电话号码进行了验证有效性。所需要的
dom4j-1.6.1.jar;geronimo-stax-api_1.0_spec-1.0.jar;poi-3.7-20101029.jar;poi-ooxml-3.7-20101029.jar;poi-ooxml-schemas-3.7-20101029.jar;xmlbeans-2.3.0.jar;
*/
public static void main(String[] args) {
Long errorMobileTotal=0L;
// 保存正确的电话号码
Set<String> mobileSet = new HashSet<String>();
try {
XSSFWorkbook wb = new XSSFWorkbook("E:/workbook1.xlsx");
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row = null;
XSSFCell cell = null;
String mobileStr="";
for (int i = 0; i <= sheet.getLastRowNum(); i++) {
row = sheet.getRow(i);
//System.out.print("第" + i + "行共" + row.getLastCellNum() +"列: ");
for (int y = 0; y < row.getLastCellNum(); y++)
{
cell = row.getCell(y);
// 设置字段为字符类型
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
// 判断储存格的格式
if (cell != null)
{
// 取得单元格的值
mobileStr = cell.getStringCellValue();
// 对手机号码进行验证身份正确
if(isMobileNO(mobileStr))
{
// 保存正确的手机号码
mobileSet.add(mobileStr);
System.out.println("号码"+mobileStr+"正确");
}
else
{
// 累计不正确的电话号码的个数
errorMobileTotal++;
System.out.println("不正确的电话号码个数:"+errorMobileTotal);
System.out.println("号码"+mobileStr+"不正确");
}
} // end (cell != null)
}// end 遍历当前行
} // end 遍历当前工作单元sheet
System.out.println("总共的行数:"+ (Long.valueOf(sheet.getLastRowNum())+1));
} catch (Exception e) {
e.printStackTrace();
}
// 因为要去除重复的所以可能有存在替换的字符
System.out.println("不正确的电话号码个数:"+errorMobileTotal);
System.out.println("正确的电话号码个数:" + mobileSet.size());
}
public static boolean isMobileNO(String mobiles){
Pattern p = Pattern.compile("^(\\+86)*0*((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
Matcher m = p.matcher(mobiles);
return m.matches();
}
2012-08-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人