Logica_
2015-07-20 02:25
采纳率: 93.5%
浏览 3.5k

如何用jquery实现点击“删除”行删除后,选项重新排列;

如何用jquery实现点击“删除”行删除后,选项重新排列;
例我增加到10行后,我点击删除选项5,剩下的行按1-9重新排列

  <script>
 function add(){
         var val = $('#limit').val();
         var lastInput = $('#contain input:last');
         var phName = lastInput.attr('placeholder');
         phName = phName.replace("选项","");
         phName = parseInt(phName,10)+1;
         if(parseInt(val,10)>=parseInt(phName,10)){
              $('<div class="inputs"><input input type="text" id="option'+(phName)+'" name="option'+(phName)+'" maxlength="30" style="width: 80% "  placeholder="选项'+phName+' " /><span onclick=del(this)>删除</span></div>').insertAfter(lastInput.parent('div'));
         }else{
             alert('超出了最大项');
         }
    }
         </script>
  <tr id="tr">
        <td class="table_th" >题目选项:      
        <td width="" id="contain">
              <div class='inputs'>
              <input type="text" id="option1" name="option1"
            maxlength="30" style="width: 80%"  placeholder="选项1" value="${questionNaireQuestion.option1 }"/><font
          color="red"> *</font></div>

              <div class='inputs'><input type="text" id="option2" name="option2"
            maxlength="30" style="width: 80%"" placeholder="选项2"value="${questionNaireQuestion.option2 }" />&nbsp;</div>

              <div class='inputs'><input type="text" id="option3" name="option3"
            maxlength="30" style="width: 80% " " placeholder="选项3"value="${questionNaireQuestion.option3 }" /><span  onclick=del(this)>删除</span></div>

              <div class='inputs'><input type="text" id="option4" name="option4"
            maxlength="30" style="width: 80% "  placeholder="选项4" value="${questionNaireQuestion.option4 }"/><span  onclick=del(this)>删除</span></div>

            <div><a href="javascript:;" class="addRow" id="addRow" onclick="javascript:add()">+添加选项</a></div>

            </td>
    </tr>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • danielinbiti 2015-07-20 02:37
    已采纳
     function renew(){
             var inputs = $('#contain input[placeholder^="选项"]') ;
             for(var i=0;i<inputs.length;i++){
                  $(inputs[i]).attr('placeholder','选项'+(i+1));
             }
             alert(inputs.length);
        }
    
     <input type="button" id="btnrefresh" name="btnrefresh" value="重新排列" onclick='renew()'/>
    
    点赞 评论

相关推荐 更多相似问题