简体   繁体   中英

How pass html code as parameter in javascript function

I want to pass html code in javascript function.

<a onclick="PreviewTemplate('<p>Test{#email}</p>')">Preview</a>

function PreviewTemplate(temp) {
            debugger;
            var contents = temp;
            var mywin = window.open("", "ckeditor_preview", "location=0,status=0,scrollbars=0,width=500,height=500");

            $(mywin.document.body).html(contents);
}

You may try the following code.

const handleOnClick = (htmlContent) => {
     `<p>Test${htmlContent}</p>`
} 

<a onclick="() => handleOnClick( " + customHtmlContent + ")">Preview</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM