jquery获取checkbox选中的值并追加到input中

    xiaoxiao2026-05-04  4

    js:

    $(function(){ $("input[name='chbox']").change(function(){ var result=""; $("input[name='chbox']:checked").each(function(){ result+=$(this).val()+','; }); if(result!=""){ result=result.substring(0,result.lastIndexOf(',')); } $("#tinput").val(result); }); }) html:

    <input type="text" id="tinput"/> <div> <input type="checkbox" name="chbox" value="aa"/>aa <input type="checkbox" name="chbox" value="bb"/>bb <input type="checkbox" name="chbox" value="cc"/>cc <input type="checkbox" name="chbox" value="dd"/>dd <input type="checkbox" name="chbox" value="ee"/>ee <input type="checkbox" name="chbox" value="ww"/>ww <input type="checkbox" name="chbox" value="rr"/>rr <input type="checkbox" name="chbox" value="hh"/>hh </div>

    转载请注明原文地址: https://ju.6miu.com/read-1309346.html
    最新回复(0)