我无法克服,我转向社区。有一个模板,我在其中通过str_replace()插入必要的参数
$output = "<div class='row'><KEYONE></div>"; //шаблон
$one_key = '<div class="card text-bg-secondary" style="width: 10rem;margin: 10px;padding: 0">'
.'<div class="card-header form_radio_btn" style="padding: 0;height: 40px;display: block"><span class="form_radio_btn" title="<KEYTITLE>" style="">'
.'<input id="radio-<KEYNUM>" type="radio" name="radio" value="<HEXKEY>"><label for="radio-<KEYNUM>"><KEY></label></span></div>'
.'<div class="card-body" style="display: table-row;margin: 0;padding: 0">'
.'<div id="key-<KEYNUM>" style="width: 90px;height: 50px;float:left;text-align: center;margin: 2px 0 0 0;color: #cbcbcb"><i class="fa fa-key fa-3x"></i></div>'
.'<button id="btnGroupVerticalDrop-<KEYNUM>" type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown" style="float: right"></button>'
.'<ul class="dropdown-menu" aria-labelledby="btnGroupVerticalDrop-<KEYNUM>" >'
.'<li><a class="dropdown-item ajax-inc" data-global=\'{"ajroute":"task_info_key","key":"<KEYNUM>"}\' href="#" >Информация по ключу</a></li>'
.'<li><a class="dropdown-item ajax-inc" href="#">Сброс ключа</a></li>'
.'</ul></div></div>';
$one_key = str_replace("<KEY>","123456",$one_key);
$one_key = str_replace("<KEYNUM>","123456",$one_key);
$one_key = str_replace("<HEXKEY>","abcdef",$one_key);
$output = str_replace("<KEYONE>",$one_key,$output);
echo $output;
一切正常,菜单扩展。我需要通过 Ajax 更新键列表,因为这个块通过按键数显示单个元素来“相乘”。我无法通过 Ajax “推动”复杂的数据全局构造(如果删除它,则一切正常)。我强调——这个块是通过替换来显示的。试图改变引号,逃避 - 没有帮助。
错误 - Uncaught SyntaxError: missing ) 在参数列表 Ajax 本身之后:
"$('#keylist').html('<div class=\"card text-bg-secondary\" style=\"width: 10rem;margin: 10px;padding: 0\"><div class=\"card-header form_radio_btn\" style=\"padding: 0;height: 40px;display: block\"><span class=\"form_radio_btn\" title=\"версия микропрограммы: 16778249\" style=\"\"><input id=\"radio-1065509103\" type=\"radio\" name=\"radio\" value=\"3f8260ef\"><label for=\"radio-1065509103\"><b>3f8260ef</b></label></span></div><div class=\"card-body\" style=\"display: table-row;margin: 0;padding: 0\"><div id=\"key-1065509103\" style=\"width: 90px;height: 50px;float:left;text-align: center;margin: 2px 0 0 0;color: #cbcbcb\"><i class=\"fa fa-key fa-3x\"></i></div><button id=\"btnGroupVerticalDrop-1065509103\" type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" style=\"float: right\"></button><ul class=\"dropdown-menu\" aria-labelledby=\"btnGroupVerticalDrop-1065509103\" ><li><a class=\"dropdown-item ajax-inc\" data-global='{\"ajroute\":\"task_info_key\",\"key\":\"1065509103\"}' href=\"#\" >Информация по ключу</a></li><li><a class=\"dropdown-item ajax-inc\" href=\"#\">Сброс ключа</a></li></ul></div></div><div class=\"card text-bg-secondary\" style=\"width: 10rem;margin: 10px;padding: 0\"><div class=\"card-header form_radio_btn\" style=\"padding: 0;height: 40px;display: block\"><span class=\"form_radio_btn\" title=\"версия микропрограммы: 16778245\" style=\"\"><input id=\"radio-1065510441\" type=\"radio\" name=\"radio\" value=\"3f826629\"><label for=\"radio-1065510441\"><b>3f826629</b></label></span></div><div class=\"card-body\" style=\"display: table-row;margin: 0;padding: 0\"><div id=\"key-1065510441\" style=\"width: 90px;height: 50px;float:left;text-align: center;margin: 2px 0 0 0;color: #cbcbcb\"><i class=\"fa fa-key fa-3x\"></i></div><button id=\"btnGroupVerticalDrop-1065510441\" type=\"button\" class=\"btn dropdown-toggle\" data-bs-toggle=\"dropdown\" style=\"float: right\"></button><ul class=\"dropdown-menu\" aria-labelledby=\"btnGroupVerticalDrop-1065510441\" ><li><a class=\"dropdown-item ajax-inc\" data-global='{\"ajroute\":\"task_info_key\",\"key\":\"1065510441\"}' href=\"#\" >Информация по ключу</a></li><li><a class=\"dropdown-item ajax-inc\" href=\"#\">Сброс ключа</a></li></ul></div></div>')"