SCRIPT1014: Invalid character - Quote symbol

跟風遠走 提交于 2019-12-05 19:38:32

It looks like you're putting backticks (`) into your string there.

onClick='myFunc(`" + ... + "`);'>

In modern browsers, backticks are used for template literals. IE11 doesn't support template literals.

Instead, try escaping your quotes:

onClick='myFunc(\"" + array[i].idAuthor + "\");'>

You should use normal quotes, but escape them so they are parsed as part of the string:

$("#id").append("<div onClick='myFunc(\"" + array[i].idAuthor + "\");'>" + i + "</div>");
//------------------------------------^^   ----------------------^^
//create element using jquery
var elm = $('<div>');

//put ID as custom attribute
elm.attr('data-author-id', array[i].idAuthor);

//put some html content for new element
elm.html(i);

// catch click on it
elm.click(function(){
    // call external function and pass your custom tag attribute as value
    myFunc( $(this).attr('data-author-id') );
});

    $("#id").append(elm);

something like that should work.

of more shot way:

$("#id").append($('<div>')
.attr('data-author-id', array[i].idAuthor)
.html(i)
.click(function(){
    // call external function and pass your custom tag attribute as value
    myFunc( $(this).attr('data-author-id') );
}));

jQuery have lot of functionality control tag attributes, events, values and lot's of useful stuff.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!