如何在echo输出的SweetAlert2代码中自定义确认按钮文本?
修改SweetAlert确认按钮文本的方法
你当前使用的是旧版SweetAlert(v1.x),可以通过以下两种方式修改确认按钮的默认"OK"文本:
方式一:按参数顺序传递
在sweetAlert函数的第四个参数位置直接传入自定义按钮文本即可:
echo '<script type="text/javascript">'; echo 'setTimeout(function () { sweetAlert("<b>Great!","Your data is sent successfully.</b>","success", "确认");'; echo '}, 500);</script>';
方式二:使用对象配置(推荐)
用对象形式传入参数,通过confirmButtonText字段指定按钮文本,这种方式更直观,也方便后续添加其他自定义配置:
echo '<script type="text/javascript">'; echo 'setTimeout(function () { sweetAlert({'; echo ' title: "<b>Great!",'; echo ' text: "Your data is sent successfully.</b>",'; echo ' type: "success",'; echo ' confirmButtonText: "确认"'; echo '});'; echo '}, 500);</script>';
注意:以上写法适配你当前使用的SweetAlert v1.x版本,如果你后续升级到v2+版本,函数名会改为Swal.fire,配置字段逻辑类似但参数结构略有不同。
内容的提问来源于stack exchange,提问作者Blind Astronome
相关产品推荐
相关产品推荐

