javascript - Placing quotes in JS parameters -
i dynamically populating unordered list js mobile app. using jquery mobile , phonegap developing.
in list want call function parameters when clicked. able call function downloadpdf() without using parameters, not if add them. think has quotes/double qoutes.
var $li = $("<li><a href='#' onclick='downloadpdf('"+val.title+"', '"+val.url+"')'>"+val.title+"</a></li>"); i not able debug running on phone, hope more trained eye able see what's wrong here. both val.title , val.url holds values of string type.
do not use inline events. using jquery, makes easy attach events
var li = $("<li><a href='#'>"+val.title+"</a></li>"); li.find("a").on("click", function(){ downloadpdf(val.title,val.url); }); or use data attributes , generic onclick handler
var li = $("<li><a class='download' href='#'>"+val.title+"</a></li>"); li.find("a").data("title", val.title).data("url", val.url); and generic click
$(document).on("click", "a.download", function (event) { var anc = $(this); downloadpdf( anc.data("title"), anc.data("url")); event.preventdefault(); }
Comments
Post a Comment