×

jQuery实现的Email中的收件人效果(按del键删除)

作者:Terry2017.02.07来源:Web前端之家浏览:10941评论:0
关键词:JQueryJS
除以下代码外,再导入个jquery-1.4.4.min.js文件 ,代码中收件人是写死的("ABC", "ABCDEF", "BCDEF"),已测试通过!
复制代码 代码如下:

<%@ page language="java" import="java.util.*" pageencoding="utf-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Cache-Control" content="no-cache">
<title></title>
<script type="text/javascript" src="jquery-1.4.4.min.js"></script>
<style>
.clickcss a:link
{
text-decoration: none;
}
.clickcss a:hover
{
background-color: #CCCCCC;
}
.clickcss a:active
{
background-color: blue;
}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(
function() {
$(document).keydown(
function(event) {
if (event.keyCode == 46) {
var containner = $("#div1 span").eq(0);
containner.find("a").each(function() {
if ($(this).css('background-color') == 'blue') {
$(this).remove();
}
});
if (containner.find("a").length == 0) {
containner.css("width", "0");
}
}
});
});
function check() {
//<%=value %>
var array = new Array("ABC", "ABCDEF", "BCDEF");
var result = null;
var aobject = null;
var value = $("#input1").val();
var containner = $("#div1 span").eq(0);
if (value == "") {
alert("请输入收件人名称!")
}
else {
result = new Array();
for (var i = 0; i < array.length; i++) {
if (contains(array[i], value, true)) {
result.push(array[i]);
}
}
if (result.length == 0) {
alert("不包含当前输入的收件人信息,请重新输入!");
}
else if (result.length == 1) {
alert("添加一个收件人!");
containner.css("width", "100%");
containner.append("<a href='javascript:' >" + result[0] + ";</a>");
}
else if (result.length > 1) {
alert("有" + result.length + "个匹配信息,弹出选择对话框选择!");
// window.open("dialog.html", "请选择", "height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no,alwaysRaised=yes,z-look=yes");
window.open("dialog.html");
}
}
}
function contains(string, substr, isIgnoreCase) {
if (isIgnoreCase) {
string = string.toLowerCase();
substr = substr.toLowerCase();
}
var startChar = substr.substring(0, 1);
var strLen = substr.length;
for (var j = 0; j < string.length - strLen + 1; j++) {
if (string.charAt(j) == startChar)//如果匹配起始字符,开始查找
{
if (string.substring(j, j + strLen) == substr)//如果从j开始的字符与str匹配,那ok
{
return true;
}
}
}
return false;
}

</script>
</head>
<body style="padding: 0 0; margin: 0 0;">
<div id="div1" style="background-color: #22dd22; width: 100%">
<span class="clickcss" style="background-color: #00ff00;"></span><span style="width: 100%">
收件人:<input id="input1" /></span>
</div>
<button id="button1" onclick="check();" />
检查</button>
</body>
</html>

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1486396800808.html

网友评论文明上网理性发言已有0人参与

发表评论: