• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Hing
沉浸在技术的海洋,通过学习与讨论,只有不断的提高,才有可能去创造与实现.
博客园    首页    新随笔    联系   管理    订阅  订阅
文本框与复选框联动---星期选择
CSS:
 .subject
        {
            border: 1px solid #E7E4E4;
            background
-color: White;
            margin
-bottom: 5px;
            margin
-top: 5px;
        }

JS:
Code
function chkCheck(chkID) {
            var text 
= document.getElementById("txtWeek");
            
if (text.value != "") {
                
if (chkID.checked) {
                    text.value 
+= "," + chkID.value;
                }
                
else {
                    var sp 
= text.value.split(',');
                    
for (var i = 0; i < sp.length; i++) {

                        
if (sp[i] == chkID.value) {
                            
if (sp[i - 1]) {
                                text.value 
= text.value.replace("," + sp[i], "");
                            }
                            
else if (sp[i + 1]) {
                                text.value 
= text.value.replace(sp[i] + ",", "");
                            }
                            
else {
                                text.value 
= text.value.replace(sp[i], "");
                            }

                        }
                    }

                }
            }
            
else {
                
if (chkID.checked) {
                    text.value 
= chkID.value;
                }
            }
        }

HTML:
Code
    <div>
        
<input name="txtWeek" type="text" maxlength="14" id="txtWeek" onfocus="this.blur()" style="cursor:pointer;" />
        
<div id="week" class="subject" style="display:none;">
            
<input type="checkbox" id="chkSunday" onclick="chkCheck(this)" value="0" title="Sunday" />Sunday
            
<input type="checkbox" id="chkMonday" onclick="chkCheck(this)" value="1" title="Monday" />Monday
            
<input type="checkbox" id="chkTuesday" onclick="chkCheck(this)" value="2" title="Tuesday" />Tuesday
            
<input type="checkbox" id="chkWednesday" onclick="chkCheck(this)" value="3" title="Wednesday" />Wednesday
            
<input type="checkbox" id="chkThursday" onclick="chkCheck(this)" value="4" title="Thursday" />Thursday
            
<input type="checkbox" id="chkFriday" onclick="chkCheck(this)" value="5" title="Friday" />Friday
            
<input type="checkbox" id="chkSaturday" onclick="chkCheck(this)" value="6" title="Saturday" />Saturday
        
</div>
        
<script type="text/javascript">
            $(
"#txtWeek").click(function() {
                var offset 
= $(this).offset();
                $(
"#week").css("left", offset.left).css("top", offset.top + 15).fadeIn("fast");
            });

            $(
"#week").hover(function() { }, function() {
                $(
this).fadeOut("fast");
            });
        
</script>
    
</div>

没有什么技术性。。。纯粹记录。
posted on 2009-09-24 11:05  Pacer  阅读(581)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3