多个文本框操作,当点击一个文本框时调出列表窗口,选择一个li时获取其值。
下列代码问题:当选择了多个文本框时,选择过的文本框值跟着一起变了
请高手帮忙,谢谢!function frshow_city(id){
    $("[id ^= 'fromcity_div']").hide();
    $('#fromcity_div' + id).show();
$('.departure_frbox li').click(function(){
$('#fromcity' + id).val($(this).text());
$('#fromcity_div' + id).hide();
})
}

解决方案 »

  1.   

         <div class="box left_mr20"><p style="margin-left:20px; text-indent:0; font-size:24px; font-family:'微软雅黑'; color:#f6bb19; line-height:2em;">东南亚/南亚</p>
            <table width="290" style="margin:18px auto;" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td width="126"><div class="citylist_hand">
        <input name="fromcity" type="text" class=" " id="fromcity1" value="广州" style="width:105px;"  onfocus="frshow_city(1);"/>
            <div id="fromcity_div1" style="background:url(images/city_bg.jpg) no-repeat; position:absolute;top:25px; left:2px; z-index:100; width:349px; height:150px; display:none;"><table width="100" border="0" cellspacing="0" cellpadding="0" style="margin-top:10px;">
      <tr>
        <td style="text-align:center; font-size:12px;"><strong>国内城市</strong></td>
      </tr>
    </table>
    <table width="340" border="0" cellspacing="0" cellpadding="0" style="margin-top:12px;">
      <tr>
        <td style="text-align:center; font-size:14px;"><ul class="departure_frbox" style="margin:0; padding:0; list-style:none; width:95%;font-size:12px;">
        <li>广州</li><li>郑州</li> <li>贵州</li><li>揭阳</li></ul></td>
      </tr>
    </table></div>
                    </div>
                  </td>
        <td width="45"><img src="images/plane1.jpg" height="19"></td>
        <td width="124"><div  class="citylist_hand">
                    <input name="tocity" type="text" class=" " id="tocity1" value="曼谷" style="width:105px;"  onfocus="toshow_city(1);" />
                    <div id="tocity_div1" style="background:url(images/city_bg.jpg) no-repeat; position:absolute;top:25px; left:2px; z-index:100; width:349px; height:150px; display:none;"><table width="100" border="0" cellspacing="0" cellpadding="0" style="margin-top:10px;">
      <tr>
        <td style="text-align:center; font-size:12px;"><strong>国际城市</strong></td>
      </tr>
    </table>
    <table width="340" border="0" cellspacing="0" cellpadding="0" style="margin-top:12px;">
      <tr>
        <td style="text-align:center; font-size:14px;"><ul class="departure_tobox" style="margin:0; padding:0; list-style:none; width:95%;font-size:12px;  ">
        <li>曼谷</li> <li>马尼拉</li> <li>新加坡</li> <li>吉隆坡</li> <li>河内</li> <li>槟城</li> <li>仰光</li> <li>暹粒</li> <li>胡志明市</li> <li>新德里</li> <li>雅加达 </li> <li>金边</li> <li>达卡</li> <li>加德满都</li>
        </ul></td>
      </tr>
    </table></div>
                    </div></td>
      </tr>
    </table>
            <div style="height:80px; width:307px; margin-left:4px; background:#f6bb19; border-top:1px solid #ff0000;border-bottom:1px solid #ff0000;">
    <p style="color:#ffffff; font-family:'微软雅黑'; margin:0 0 0 10px; text-indent:0em; ">往返价格:</p>
    <p style="color:#ffffff; font-family:'微软雅黑'; font-size:38px; line-height:1.5em; font-weight:600; margin:5px 0 0 90px; line-height:1em;text-indent:0em; "><span style="color:#fce7a6;">CNY</span> 330 <span style=" font-size:18px;color:#fce7a6;">起</span></p></div>
    <div class="grid" style="width:220px; margin:0 auto; padding-bottom:12px; padding-top:12px; overflow:auto;">
              <div id="segtype" style="padding-bottom:5px;">
                <input type="radio" class="fixps" name="segtype_1" value="S" id="s_class" />
                <span class="p_r">单程</span>
                <input type="radio" class="fixps" name="segtype_1"  value="R" id="r_class" />
                <span class="p_r">往返程</span> </div>
                  <div class="grid1">
                    <span style="margin:0; text-indent:0;  font-size:12px; float:left;">出发日期:</span>
                    <input value="2013-05-17" style="background-position: right -510px; background-color:#ffffff;" name="DepartureDate" id="DepartureDate1" class="xinput" readonly="readonly" type="text">
                <a href="javascript:void(0)" class="selectdate dp-choose-date" style="display:none;">选择出发日期</a></div><br/>
                <div style="padding-top:10px;" class="returndate_xs">
                    <span style="margin:0; text-indent:0;  font-size:12px; float:left;">回程日期:</span>
                    <input type="text" name="ReturnDate" id="ReturnDate1" class="xinput " readonly="readonly" style="background-color:#ffffff;" value="2013-05-20" />
                    <a href="javascript:void(0)" class="selectdate dp-choose-date" style="display:none;">选择回程日期</a> </div>
              </div>
         <div style="width:160px; margin-left:70px;"><label style="font-size:12px;">成人:</label> <select name="adult" id="adult1" onchange="refreshChild1(this.value);">
                  <option value="1" selected="selected">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
                  <option value="5">5</option>
                  <option value="6">6</option>
                  <option value="7">7</option>
                  <option value="8">8</option>
                  <option value="9">9</option>
                </select>
         </div>
         <div style="width:141px; height:53px; margin:25px auto; margin-bottom:0;"><a href="javascript:void(0);" onclick="submitform2(1);"><img src="images/search1.jpg"></a></div>
      </div>
      

  2.   

    LZ,加个alert检查下$('#fromcity' + id).lengthfunction frshow_city(id){
        $("[id ^= 'fromcity_div']").hide();
        $('#fromcity_div' + id).show();
        alert($('#fromcity' + id).length);
        $('.departure_frbox li').click(function(){
            $('#fromcity' + id).val($(this).text());
            $('#fromcity_div' + id).hide();
        })
    }
      

  3.   

    点过几个文本框就会弹出几个值为1的窗口
    LZ再检查下click事件里id的值$('.departure_frbox li').click(function(){
        $('#fromcity' + id).val($(this).text());
        $('#fromcity_div' + id).hide();
    })
      

  4.   


    function frshow_city(id){
        $("[id ^= 'fromcity_div']").hide();
        $('#fromcity_div' + id).show();
    $('.departure_frbox li').each(function(i, dom) {
        $(dom).click(function() {
    $('#fromcity' + id).val($(this).text());$('#fromcity_div' + id).hide();});
    });
    } 闭包的问题
      

  5.   


    function frshow_city(id){
        $("[id ^= 'fromcity_div']").hide();
        $('#fromcity_div' + id).show();
    $('.departure_frbox li').each(function(i, dom) {
        $(dom).click(function() {
    $('#fromcity' + id).val($(this).text());$('#fromcity_div' + id).hide();});
    });
    } 闭包的问题没有效果,还是一样的问题