简体   繁体   中英

Javascript syntax for concatenating strings + variables inside of function

In line 5 below I'm attempting to concatenate a variable inside of two strings such that the resulting HTML string inside of my javascript looks like this <iframe src="ImageUpload.aspx?ID=Foo" width="100%" height="100%" frameborder="0"></iframe>

Here's my javascript as I've written it. What is the correct syntax for line #5? Everything else is correct.

if (buttontext == "Add Photo Log") {
    var mastertable = $find("<%=RadGrid1.ClientID %>").get_masterTableView();
    var PackageID = mastertable.get_dataItems()[0].getDataKeyValue("PackageID");

    $.fancybox(
        '<iframe src="ImageUpload.aspx?ID=' +PackageID '" width="100%" height="100%" frameborder="0"></iframe>',
        {
            'autoDimensions': false,
            'width': 700,
            'height': 'auto',
            'transitionIn': 'none',
            'transitionOut': 'none'
    });
}

You've almost got it. Add another + after PackageID

'<iframe src="ImageUpload.aspx?ID=' + PackageID + '" width="100%" height="100%" frameborder="0"></iframe>'

There is a + missing:

'<iframe src="ImageUpload.aspx?ID=' +PackageID+ '" width="100%" height="100%" frameborder="0"></iframe>',

You missed a "+"

'<iframe src="ImageUpload.aspx?ID=' +PackageID+ '" width="100%" height="100%" frameborder="0"></iframe>',
'<iframe src="ImageUpload.aspx?ID=' + PackageID + '" width="100%" height="100%" frameborder="0"></iframe>'

You were missing 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