将javascript变量传递给内联html onclick函数

时间:2017-11-18 11:21:10

标签: javascript jquery html ajax

我试图将变量传递给内联onclick函数但没有成功。我已经尝试过搜索,但是我遵循了这个但是在参数列表之后出现了错误(Uncaught SyntaxError:missing): pass string parameter in an onclick function

google.maps.event.addListener(marker, "click", function(e) {
infoWindow.setContent(data.name+ "<br> '<input type="button"onClick="Myfunction(\'' + data.name + '\')" />');
infoWindow.open(map, marker);
});

我想在my函数(data.name);

中传递data.name结果

我想在myfunction中处理这个结果的另一件事是从Mysql php数据库加载图像我应该使用Ajax吗?

2 个答案:

答案 0 :(得分:0)

错误是由于您的字符串无效而引起的:

google.maps.event.addListener(marker, "click", function(e) {

    var contentString = '<h3>'+data.title+'</h3></br><input type="button"onClick="Myfunction(' +data.title+ ')" />';

    infoWindow.setContent(contentString);                
    infoWindow.open(map, marker);    
});

答案 1 :(得分:0)

infoWindow.setContent(data.name+ "<input type=button onClick=Myfunction("+ data.name +") />");
相关问题