我想做一个类似校内网上赠送礼物时选择好友的过程,单击“添加好友时”就会弹出选择好友对话框,在复选框中选择一个好友名称,上面的文本框就会添加一个名称(注:是以一个整体形式显示的),这样删除时单击“删除”就可以完整删除一个名称,不会导致删除不完整的名称。功能叙述如上。
问题如下:1.选择复选框时可以实时添加名称到文本框。这个我觉得可以利用复选框的checked来确定。(这个已搞定)2、添加复选框选好的名称到文本框时, 如何实现名称整体显示后面还加一个删除图标。
望各位大侠指点迷津,若有相关案例不胜感激
问题如下:1.选择复选框时可以实时添加名称到文本框。这个我觉得可以利用复选框的checked来确定。(这个已搞定)2、添加复选框选好的名称到文本框时, 如何实现名称整体显示后面还加一个删除图标。
望各位大侠指点迷津,若有相关案例不胜感激
解决方案 »
- js 比较运算会将数据类型转换成什么?
- div 上下总是空了一段,好像是滚动条在起作用,怎么让他撑满工作区域?
- 各位大大,小弟求教啊。HTM 调用 JS 的问题
- msn space live里面关于层拖动的特效实现的原理是..?
- 弱问各问前辈:如何引用带下标变量?[up有分]
- 如何判断内涵数执行完毕?
- 如何用javascript/asp/php获取客户端.net框架安装版本号
- 我要获得一个弹出窗口的返回值,有无类似vbscript中msgbox的函数
- 请问如何捕捉鼠标点击事件
- 多选框的选择顺序问题
- dojo如何能实现像jquery $().next()那样指定下一个节点
- 求助ExtJS的一个问题(Ext 未定义)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>js 文本框效果</title>
<style type="text/css">
.inputs{width:600px;height:auto; border:1px solid #ddd;margin:100px auto;line-height:20px;}
.divInputs{width:auto;height:auto;line-height:20px;min-height:20px; }
.divHistory{height:20px;width:auto;line-height:20px;float:left;display:inline; margin:0px 3px; background-color:#dee;
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 不换行 */}
.clear{clear:both;} </style>
</head>
<body><div class="inputs" id='inputs'>
<div class="divInputs" id='divInputs'>
<input type='text' value="" style="float:left;border:0px;height:20px; " id='txtInput'/>
<div class='clear'></div>
</div>
</div>
<input type='button' value="查看设置的值" id="btn"/>
</body>
<script type="text/javascript">window.onload=function()
{
var inputs=[];
var txtInput = document.getElementById("txtInput");
var divInputs = document.getElementById("divInputs");
document.getElementById("btn").onclick=function(){
alert(inputs);
} ;
document.getElementById("inputs").onclick=function(){
txtInput.focus();
} ;
txtInput.onkeydown=function(e)
{
e=e||event;
if(e.keyCode==13){ // 回车
var input = txtInput.value.trim();
if(input==""){
return;
}
if(inputs.indexOf(input)>-1){
alert("内容已存在");
return;
}
var div = document.createElement("div");
div.innerHTML ="<span>" +input+"</span>";
div.className="divHistory";
var span = document.createElement("span");
span.style.cssText ="top:0px;right:0px;position:relative;z-index:99999;font-size:12px; border:1px solid red;";
span.innerHTML="X";
div.appendChild(span);
divInputs.insertBefore(div,txtInput);
inputs.push(input);
txtInput.value ="";
span.onclick=function(){
this.parentNode.parentNode.removeChild(this.parentNode);
inputs.remove(input);
};
}
};
};
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g,'');
};
Array.prototype.indexOf=function(value){
if(this!=null && this.length>0){
for(var i=0;i<this.length;i++)
{
if(this[i]==value){ return i;}
}
}
return -1;
};
Array.prototype.removeAt=function(index){
this.splice(index,1);
}
Array.prototype.remove=function(obj){
var index=this.indexOf(obj);
if (index>=0){
this.removeAt(index);
}
}
</script>
</html>