我正在 Contact7 电子邮件表单中通过 javascript 覆盖一些 HTML 代码。
我有 3 个“p”标签,但我想不出一种方法可以使其更加干燥。
这是我的代码
//remove default HTML//
document.querySelector('.wpcf7-response-output').innerHTML = '';
//Add first p tag and text//
var p1 = document.createElement('p');
p1.innterHTML ="Thank you for your order!";
document.querySelector('.wpcf7-response-output').appendChild(p1);
//Add second p tag and text//
var p2 = document.createElement('p');
p2.innerHTML = "A confirmation email has been sent to you from info@iscafit.com.";
document.querySelector('.wpcf7-response-output').appendChild(p2);
//Add third p tag and text//
var p3 = document.createElement('p');
p3.innerHTML = "Please keep the confirmation email for your records."
document.querySelector('.wpcf7-response-output').appendChild(p3);
结果 html 应该是
<div class=".wpcf7-response-output">
<p>Thank you for your order!</p>
<p>A confirmation email has been sent to you from info@iscafit.com.</p>
<p>Please keep the confirmation email for your records.</p>
</div>
我是一名初级开发人员,试图更好地编写 DRY 代码。任何建议,将不胜感激!
慕的地10843
胡子哥哥
相关分类