Вы должны избежать "
символов в значениях свойств ... Используйте "
special entity:
html = '<a href="#" onclick="alert("This link is clickable only in the mobile!")">text</a>'
Есть лучшие варианты для достижения этой цели, вместо того, чтобы писать сырой HTML в JavaScript.
jQuery:
var aElement = jQuery("<a>").attr("href", "#").click(function() {
alert("This link is clickable only in the mobile!");
});
// You can append it like:
aElement.appendTo(document.body);
Pure Javascript:
var aElement = document.createElement("a");
aElement.setAttribute("href", "#");
// If you want the onclick attribute to show up in HTML source:
aElement.setAttribute("onclick", "alert(\"This link is clickable only in the mobile!\")");
// This way is easier:
aElement.onclick = function() {
alert("This link is clickable only in the mobile!");
}
// Append like:
document.body.appendChild(aElement);
Проблема с кавычками вложенности, использование внутри предупреждения – Tushar
Я рекомендую вам не использовать встроенные обработчики, используйте 'addEventListener' для привязки событий – Tushar