首页 > 解决方案 > WhatsApp 按钮中的 Onclick 功能

问题描述

我在将输入发送到数据库的订单按钮中有 onclick 功能,在修改按钮后(将其连接到 WhatsApp 而不是数据库)onclick功能已停止工作......我需要该onclick功能才能工作。

<form className="orderForm">
    <div className="form-group">
        <div className="whatsapp" style="margin-top: 20px;">
            <button
                className="btn-primary"
                onClick="reportConversion(event.target)"
                type="submit"
                style="height:70px;width: 100%;"
            >
                <img
                    src="wat.png"
                    style="width: 36px;height: 36px; position: absolute; margin-left: -40px;margin-top: -10px;"
                />
                <a href="https://wa.me/......" style="color: white;font-weight: 600; font-size: 18px;">
                    ...text...
                </a>
            </button>
        </div>
    </div>
</form>

标签: javascripthtml

解决方案


使用 a 会是一个很好的解决方案Promse,但是reportConversion返回未知,也不确定我们可以修改它吗?

无论如何,由于我们具有链接优先级,因此该解决方案可能适合。

注意:请记住将<button>类型从更改submitbutton并从内部删除链接。

function reportConversionWrapper(target) {
  reportConversion(target);
  setTimeout( function() {
    window.location.href = 'https://wa.me/......';
  }, 1000 );
}
// following is just a filler - don't mind it
function reportConversion(a) {
  return;
}
<form className="orderForm">
    <div className="form-group">
        <div className="whatsapp" style="margin-top: 20px;">
            <button
                className="btn-primary"
                onclick="reportConversionWrapper(event.target)"
                type="button"
                style="height:70px;width: 100%;"
            >
                <img
                    src="wat.png"
                    style="width: 36px;height: 36px; position: absolute; margin-left: -40px;margin-top: -10px;"
                />...text...
            </button>
        </div>
    </div>
</form>


推荐阅读