jquery文本框显示多选框的选择结果

来源:互联网 发布:华中数控编程软件 编辑:程序博客网 时间:2024/04/29 01:15
 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="jquery-1.4.4.js" type="text/javascript"></script>
<script language="javascript">
$(document).ready(function(){
    var val="";
  $(".sourcecheck").each(function(){
        $(this).click(function(){
  
   if($(this).attr('checked')==true)
    {
       val+=$(this).attr("value")+'+';
    }
    else
    {
      
    if(val.indexOf($(this).attr("value")) >=0)
    {
      
       val=val.replace($(this).attr("value")+'+',"");
    
    }
   
    }
    $("#txtConsult").val(val);
  });
   });

});


</script>

</head>

<body>
<input id="txtConsult" type="text" maxlength="50" readonly="readonly" class="txtHInput"/>
<input type="checkbox" class="sourcecheck" name="sourcecheck" value="电话" />电话
<input type="checkbox" class="sourcecheck" name="sourcecheck" value="网站咨询" />网站咨询
<input type="checkbox" class="sourcecheck" name="sourcecheck" value="短信" />短信
<input type="checkbox" class="sourcecheck" name="sourcecheck" value="本院" />本院
<input type="checkbox" class="sourcecheck" name="sourcecheck" value="活动现场" />活动现场
</body>
</html>

原创粉丝点击