我需要的是能够将字符串传递给javascript函数,该函数在div的onclick事件中指定,
$("#div").html("<div id='suggestion' onclick='storetag("+response[i]['tagname']+")'><div id='postag' ><center><b>"+response[i]['tag']+"</b></center></div></div>");
在这里,我无法将response [i] ['tagname']传递给storetag(),因为它是一个字符串,并且要求在其周围有基调
您需要将引号放在值周围的字符串中:
$("#div").html("<div id='suggestion' onclick='storetag(\""+response[i]['tagname']+"\")'><div id='postag' ><center><b>"+response[i]['tag']+"</b></center></div></div>");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句