簡體   English   中英

Wordpress中Contact Form 7中如何包含JS

[英]How to include JS in Contact Form 7 In Wordpress

我的這段代碼有問題。 我希望你們能幫助我解決這個問題。 我想在這里做的是驗證 Contactform 7 的 [輸入文本],用戶只能在輸入中鍵入數字。 我有這個作為參考包括 JS 聯系表格 7 Wordpress這樣做。 所以我想在我的函數 php 上創建這個腳本的簡碼,然后按照上面鏈接中的建議在聯系表中使用這個簡碼。 這是我目前在我的函數中遇到的錯誤。php

由於文件 wp-content/themes/capital/functions.php 的第 262 行錯誤,您的 PHP 代碼更改被回滾。 請修復並再次嘗試保存。 語法錯誤,意外的“<”

function input_cf7() {

<script>

        var userName = document.querySelector('#numberField');

        userName.addEventListener('input', restrictNumber);
        function restrictNumber (e) {  
        var newValue = this.value.replace(new RegExp(/[^\d]/,'ig'), "");
        this.value = newValue;

        }

</script>

}

add_shortcode('input_validation', 'input_cf7');

腳本標簽在 html 中,它不會在 php 塊中運行,因此您必須在腳本標簽之前關閉 php 塊,並在腳本標簽之后打開 php 塊

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM