我正在使用 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)
}