2 yjwzsrzj YJWZSRZJ 于 2017.09.09 22:55 提问

js 页面搜索取值,取不出来 5C
 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个回答

YJWZSRZJ
YJWZSRZJ   2017.09.10 08:45

自己顶一下,不会,??????

YJWZSRZJ
YJWZSRZJ   2017.09.10 11:22

function loadData(option) {
$.ajax({
type : 'post', //传输类型
async : false, //同步执行
url : 'billecharts.action', //web.xml中注册的Servlet的url-pattern
data : {},
dataType : 'json', //返回数据形式为json
success : function(result) {
if (result) {
//初始化xAxis[0]的data
option.xAxis[0].data = [];
for (var i=0; i<result.length; i++) {
option.xAxis[0].data.push(result[i].bi_date);
}
//初始化series[0]的data
option.series[0].data = [];
for (var i=0; i<result.length; i++) {
option.series[0].data.push(result[i].expend);
}

                option.series[1].data = [];
                for (var i=0; i<result.length; i++) {
                    option.series[1].data.push(result[i].income);
                }
            }
        },
        error : function(errorMsg) {
            alert("加载数据失败");
        }
    });//AJAX
}//loadData()
var myChart = echarts.init(document.getElementById('main'));
var option = {
    tooltip : {
        show : true
    },
    legend : {
        data : [ '支出','收入' ]
    },
    xAxis : [ {
        type : 'category',
    } ],
    yAxis : [ {} ],
    series :[{
        name : '支出',
        type : 'bar',
    },
    {
        name : '收入',
        type : 'bar',
    }

    ]
};
//加载数据到option
loadData(option);
//设置option
myChart.setOption(option); 
showbo
showbo   Ds   Rxr 2017.09.10 12:05
luzifeng
luzifeng   2017.09.11 12:00

你在for循环里做这个操作肯定吧:
if(searchucard==ucard.substring(0,nameLength)){
var currentRow=resultTable.row.length;
var NewRow=resultTable.insertRow(currentRow);
。。。

能说一下到哪一步还正确么?这个用debugger调试一下,应该不难解决。

Csdn user default icon
上传中...
上传图片
插入图片