我有这个 JSON 格式的字符串:
"message": "<?= __('I agree to the <a>Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"
我想做的是给这个表单的字符串添加一个链接
"message": "<?= __('I agree to the <a href="%1">Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"
但是当我这样做时,出现以下错误:
SyntaxError: Unexpected token h in JSON
如何以正确的方式将链接添加到标签?
最佳答案
您必须像这样转义字符串中的双引号:
"message": "<?= __('I agree to the <a href=\"%1\">Terms of Service</a>', $block->getUrl('terms-conditions')) ?>"
关于javascript - 格式化 JSON 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55827463/