0

我正在使用 jquery 在我的页面中获取 rails Html 代码..所以我正在使用此代码:-

$("#but").html( ''+
    '<div class = "newb">'+
        '<table>'+
            '<tr>'+

                '<%= link_to "Add a Patient", "/outpatient_detail",:class=>"btn btn-primary",:style=>"color:white" %>'+
                '<%= form_tag("/PatientManagement/delete", method: "post",:id=>"testform") do %>'+
                '<%= text_field_tag "patientIdsDel",nil,:type=>"hidden" %>'+
                '<%= text_field_tag "hospitalId",current_user.hospital.id,:type=>"hidden"%>'+
                '<%= text_field_tag "processType","outpatient",:type=>"hidden"%>'+
                '<%= text_field_tag "finalJson","",:type=>"hidden"%>'+
                '<%= text_field_tag "imppath",@pathimp[0],:type=>"hidden"%>'+
                '<%= text_field_tag "exportP",@pathimp[7],:type=>"hidden"%>'+
                '<%= submit_tag "Delete Selected",:id=>"2",:onclick => "return del()",:class=>"btn btn-primary"%>'+
                '<%end%>'+

            '</tr>'+
        '</table>'+
    '</div>'
     );

此代码在 google chrome 、safari 中运行良好,但在 FF、IE、Opera 中无法运行。那么我该如何解决呢?它生成的html是:- 在此处输入图像描述

我的 del() 是

function del(){
        //alert("in del")
    var arl=document.getElementById("patientIdsDel").value=keys(arr);
  //alert(arl)
    var tempA = keys(arr)


    for(var i=0;i<tempA.length;i++){
        tempA[i]+'"'+":"+arr[tempA[i]]
    }


    var hid=document.getElementById("hospitalId").value;
    var ptype=document.getElementById("processType").value;
    //alert(ptype+hid)


     var jsonObj = {

             "hospitalId": hid,
             "processType":ptype
         };

    var patientIDs = {};

    for(var i=0;i<tempA.length;i++){

        patientIDs[tempA[i]] = arr[tempA[i]];

    }     


        jsonObj["patientIDs"]=patientIDs;
         var jsonString = JSON.stringify(jsonObj);

         // alert(jsonString)

         var ee= document.getElementById("patientIdsDel").value=jsonString;
    if(arl==0)
    {
        alert("No Records Selected")
        return false
    }else
    {


        return true
    }

  }

这是我的 arr 描述我如何更新它

if(selected==true){
  if(arr[model.attributes.PatientId]==undefined)
  {

    arr[model.attributes.PatientId] =  "'"+model.attributes.MeasureCategory+"'";

  }  else
  {
    arr[model.attributes.PatientId]=arr[model.attributes.PatientId]+",'"+model.attributes.MeasureCategory+"'";

  } 




    // arr[model.attributes.PatientId] =  "'"+model.attributes.MeasureCategory+"'";



  }
  else if(selected==false){
    var str=arr[model.attributes.PatientId];
    var n =arr[model.attributes.PatientId].split(",");
    var len=n.length;
    if(len==1)
    {
        delete arr[model.attributes.PatientId];
        //alert(arr[model.attributes.PatientId])
    }
    else{
        for(i=0;i<=len;i++)
    {
        if(n[i]=="'"+model.attributes.MeasureCategory+"'")
        {
            if(i==len-1)
                str=str.replace(",'"+model.attributes.MeasureCategory+"'","");
            else
                str=str.replace("'"+model.attributes.MeasureCategory+"',","");

            arr[model.attributes.PatientId]=str;
            //alert(arr[model.attributes.PatientId])

        }
    }
    // alert(n[0]+","+n[1])
    // alert(model.attributes.MeasureCategory)



    }
4

1 回答 1

0

My feeling is you have some 'syntax' error in your del function.

Can you paste all your code, what is keys(arr) ?

Also please note each line must end with ; in javascript. Depending on browser you are, it can be not interpreted or generating an error.

var arr = new Array();
function del(){
var arl=document.getElementById("patientIdsDel").value=keys(arr);
var tempA = keys(arr);

for(var i=0;i<tempA.length;i++){
    tempA[i]+'"'+":"+arr[tempA[i]];
}

var hid=document.getElementById("hospitalId").value;
var ptype=document.getElementById("processType").value;

 var jsonObj = {

         "hospitalId": hid,
         "processType":ptype
     };

var patientIDs = {};

for(var i=0;i<tempA.length;i++){
    patientIDs[tempA[i]] = arr[tempA[i]];
}     


    jsonObj["patientIDs"]=patientIDs;
     var jsonString = JSON.stringify(jsonObj);

     var ee= document.getElementById("patientIdsDel").value=jsonString;
if(arl==0)
{
    alert("No Records Selected");
    return false;
}else
{
    return true;
}
}
于 2013-09-11T11:58:05.070 回答