>>\');" />
开发者

Using Jquery append() to build html and pass null javascript values

开发者 https://www.devze.com 2023-03-13 18:27 出处:网络
Here is my code: $(\'#pageForward\').append(\' detailUser +\',\'+ detailDate +\',\'+ detailUserName + \',\'+ previousPage +\');\"开发者_开发技巧> >>\');

Here is my code:

$('#pageForward').append(' detailUser +','+ detailDate +','+ detailUserName + ','+ previousPage +');"开发者_开发技巧> >>');

The string builds, but if my variables are null, I get a syntax error:

[Break On This Error] getSDDetailPopUp(Accounting,,,,2);

How do I get this string to be this: getSDDetailPopUp(Accounting,'','','',2);

Thanks!


use || as a null coalescing operator.

... detailUser || "" + ...


For each of your params you can just do...

(detailUser != null ? detailUser : "''")

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号