'); $("body").append($temp); $temp.val(content).select(); // 执行复制 try { var successful = document.execCommand('copy'); if (successful) { // 显示成功提示 Dcat.success('复制成功'); } else { Dcat.error('复制失败'); } } catch (err) { // 使用现代API作为备选方案 if (navigator.clipboard) { navigator.clipboard.writeText(content).then(function() { Dcat.success('复制成功'); }).catch(function() { Dcat.error('复制失败'); }); } else { Dcat.error('浏览器不支持复制功能'); } } $temp.remove(); }); JS; Admin::script($script); } /** * 渲染复制按钮 * * @return string */ public function render() { $this->addScript(); $value = Helper::htmlEntityEncode($this->value()); if ($this->value() === '' || $this->value() === null) { return '
'; } $label = $this->label; $id = $this->id(); $html = <<{$value}
复制