2 回答
TA贡献1785条经验 获得超8个赞
创建一个函数,您可以使用要附加的文本进行调用p:
const container = document.querySelector('.wpcf7-response-output');
container.innerHTML = '';
const append = (text) => {
container.appendChild(document.createElement('p')).textContent = text;
};
append('Thank you for your order!');
append('A confirmation email has been sent to you from info@iscafit.com.');
append('Please keep the confirmation email for your records.');
或者只是分配新的 HTML 字符串:
document.querySelector('.wpcf7-response-output').innerHTML = `
<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>
`;
TA贡献1825条经验 获得超6个赞
干得好。您可以通过这种方式消除重复,同时保持函数的通用性。
泛化能力极大地有助于减少代码。下面的appendChild函数不仅可以用于此父子组合,还可以用于任何其他父子组合。
'''
function appendChild(parentSelector,childTagname,innerhtml)
{
var childel = document.createElement(childTagname);
childel.innterHTML =innerhtml;
document.querySelector(parentSelector).appendChild(childel);
}
appendChild('.wpcf7-response-output','p',"Thank you for your order!");
appendChild('.wpcf7-response-output','p',"A confirmation email has been sent to you from info@iscafit.com.");
appendChild('.wpcf7-response-output','p',"Please keep the confirmation email for your records");
'''
添加回答
举报