2012-11-25 23 views
1
$("#radio5").click(function() 
{ 
    document.getElementById("ti").style.display="table"; 
     $.ajax 
     ({ 
      type:"GET", 
      url:"inst.php", 
      dataType:"xml", 
      success: xmlInstructor 
     }); 
}); 


function xmlInstructor(xml) 
{ 

    $(xml).find('Instructor').each(function() 
    { 

    instructorName = $(this).find('InstructorName').text(); 

     $("#ti").append("<tr><td>"+"<input type='button' id='instructorButton' onclick='i_click("+instructorName+")' value='ADD' />"+"</td><td>"+instructorName+"</td></tr>"); 
    });   
} 

代码工作正常,直到这里。但我想警惕i_click函数,我无法得到的instructorName。如果我传递整数它的作品,但不是与字符串。jquery函数不提醒字符串

function i_click(instructorName) 
{ 
    alert(instructorName); 
    } 

无法提醒教师。

回答

2

它,因为字符串参数不带引号的

周边替换此

<input type='button' id='instructorButton' 
         onclick='i_click("+instructorName+")' value='ADD' /> 

随着

<input type=\"button\" id=\"instructorButton\" 
     onclick=\"i_click('" +instructorName +"')\" value=\"ADD\" /> 

这将解决您的问题。

+0

谢谢youuu !!!!!!!!!! – niketshah90