YJWZSRZJ
一只会飞的白菜
2017-09-09 14:55

js 页面搜索取值,取不出来

5
  • javascript
 function doSearch(){
            var searchucard=document.getElementById("search").value;
            if(searchucard==""){
                alert("请输入身份证");
                return;
            }
            var nameLength=searchucard.length;
            var table = document.getElementById("dg");
            var rowsLength = table.row.length;
            console.log(rowsLength); 
            var resultTable=document.getElementById("dg");
            var resultLength=resultTable.row.length;
            console.log(resultLength); 
            while(resultLength>0){
                resultTable.deleteRow(resultLength-1);
                resultLength--;
            }
             for(i=0;i<rowsLength;i++){
             //根据姓名搜索
                 if(searchucard!=""){
                 //找到姓名那一列
                    var ucard=table.row[i].cells[1].innerText;
                    var cellsLength=table.row[i].cells.length;

                      alert(cellsLength);
                    if(searchucard==ucard.substring(0,nameLength)){
                        var currentRow=resultTable.row.length;
                        var NewRow=resultTable.insertRow(currentRow);
                        for(j=0;j<cellsLength;++j){
                            newCell=NewRow.insertCell(j);                   
                            newCell.innerText= table.row[i].cells[j].innerText;
                        }
                    }
                }
         } 
} 
 $(function(){
    $("#dg").edatagrid({
        pageList:[5,10,20],
        fitColumns :true,
        pageSize:5,
        url:'json.action',
        remoteSort: false,
        pagination:true,
        toolbar:'#toolbar',
        columns:[[
                  {field:'uid',title:'编号',width:80},
                  {field:'uname',title:'名字',width:80,editor:{type:'text',options: {required: true}}},
                  {field:'ucard',title:'身份证',width:80,editor:{type:'text',options: {required: true}}},
                  {field:'ugender',title:'性别',width:80,editor:{type:'text',options: {required: true}},sortable:true,formatter:function(value,index,row){
                      if(value==1){
                          return '男';
                      }else if(value==2){
                          return '女';
                      }
                  },
                  editor:{
                        type:'combobox',
                        options:{
                            valueField:'rstateid',
                            textField:'text',
                            url:'data',
                            panelHeight:'auto',
                            required:true,  
                            data:[{
                                 rstateid:1,
                                 text: '男'
                                 },{
                                rstateid: 2,
                                 text: '女',
                               }]
                        }}},
                  {field:'uphone',title:'电话',width:100,editor:{type:'text',options: {required: true}}},
                  {field:'ucount',title:'人住人数',width:100,editor:{type:'text',options: {required: true}}}
              ]]
    })
    var row = $('#dg').datagrid('reload');
}); 
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答

为你推荐

换一换