本帖最后由 zjl2468 于 2009-09-13 13:39:27 编辑

解决方案 »

  1.   


    <html> 
    <head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"> </script> 
      <script type="text/javascript"> 
          $(document).ready(function() {
             var s = $("#Meal").val();
             s = s.replace(/\s/g,"");
             s = "," + s + ",";
              $("input[name='meal1']").each(function(){
                var t = "," + $(this).val() + ",";
                if(s.indexOf(t)!=-1) $(this).attr("checked", true);
                else $(this).attr("checked", false);
              });
              $("#btn").click(function(){
                 var s = ""; 
                $("input[name='meal1']:checked").each(function(){
                   s += $(this).val() + ",";
                 });
                 if(s!="") s = s.substr(0,s.length-1);
                 $("#Meal").val(s);
              });
          }); 
        
      </script> 
    </head> <body> 
    <form> 
    <input type="text" id="Meal" name="Meal" value="早餐,上午茶歇,午餐"/> 
    <input type="checkbox" name="meal1" value="早餐"  checked >早餐 
    <input type="checkbox" name="meal1" value="上午茶歇">上午茶歇 
    <input type="checkbox" name="meal1" value="午餐"  >午餐 
    <input type="checkbox" name="meal1" value="下午茶歇" >下午茶歇 
    <input type="checkbox" name="meal1" value="酒会" >酒会 
    <input type="checkbox" name="meal1" value="晚宴" >晚宴 <button type="button" id="btn">Create </button> 
    </form> 
    </body>
      

  2.   

    谢谢hookee的指导,圆满结帖!