Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在wordpress中运行多个js脚本_Javascript_Jquery_Wordpress - Fatal编程技术网

Javascript 在wordpress中运行多个js脚本

Javascript 在wordpress中运行多个js脚本,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我试图在wordpress function.php中运行两个脚本,一个用于输入屏蔽,另一个用于邮政编码搜索api。 我设法让每一个脚本分别工作,但一旦我把它们放在一起,似乎每个脚本都取消了另一个 其主要思想是屏蔽电话和邮政编码输入,并通过api验证邮政编码,完成地址和城市 抱歉,如果这是一个重复的主题,但我无法设法让它与我在网上找到的参考工作 吼叫我的剧本 function mascara_cadastro_cliente(){ if( is_page('cadastrar') ){

我试图在wordpress function.php中运行两个脚本,一个用于输入屏蔽,另一个用于邮政编码搜索api。 我设法让每一个脚本分别工作,但一旦我把它们放在一起,似乎每个脚本都取消了另一个

其主要思想是屏蔽电话和邮政编码输入,并通过api验证邮政编码,完成地址和城市

抱歉,如果这是一个重复的主题,但我无法设法让它与我在网上找到的参考工作

吼叫我的剧本

function mascara_cadastro_cliente(){

    if( is_page('cadastrar') ){
        wp_register_script('masked-input', 'https://example.com/'.'/js/jquery.maskedinput.min.js', array('jquery'));
        wp_enqueue_script ('masked-input');


        wp_register_script('valida-cep', 'https://example.com/'.'/js/jquery.min.js', array('jquery'));
        wp_enqueue_script ('valida-cep');
    }
}
add_action('wp_enqueue_scripts', 'mascara_cadastro_cliente');

函数激活屏蔽输入(){
如果(是第页(“地籍”){
?>
jQuery(函数($){
$(#注册#账单(邮政编码))掩码(“99999-999”);
$(“#reg#u计费电话”)掩码(“(99)99999-9999”);
});
$(文档).ready(函数(){
函数linpa_formulário_cep(){
//林帕·瓦洛雷斯在塞普河上。
$(“#注册#账单(地址)1”).val(“”);
$(“#bairro”).val(“”);
美元(“#reg#u shipping_city”).val(“”);
$(“#uf”).val(“”);
$(“#ibge”).val(“”);
}
//我们将继续努力。
$(“#注册#账单(邮政编码)”).blur(函数(){
//新华社“cep”somete com dígitos。
var cep=$(this.val().replace(/\D/g');
//核实是否有必要提供信息。
如果(cep!=“”){
//在CEP中表达定期有效性。
var validacep=/^[0-9]{8}$/;
//Valida o formato do CEP。
if(有效性试验(cep)){
//Preense os campos com“…”enquanto咨询网站服务。
$(“#reg#u billing_address_1”).val(“…”);
$(“#bairro”).val(“…”);
美元(“#reg#u shipping_city”).val(“…”);
$(“#uf”).val(“…”);
美元(“#ibge”).val(“…”);
//viacep.com网站服务咨询公司。br/
$.getJSON(“https://viacep.com.br/ws/“+cep+”/json/?回调=?”,函数(DADO){
if(!(“护墙板中的erro”){
//阿图利萨酒店。
$(“#reg#u billing_address_1”).val(dados.logradouro);
$(“#bairro”).val(dados.bairro);
$(#reg#u shipping_city”).val(dados.localidade);
$(“#uf”).val(dados.uf);
$(“#ibge”).val(dados.ibge);
}//如果是,则结束。
否则{
//这是一个很好的例子。
limpa_formulário_cep();
警惕(“CEP não encontrado.”);
}
});
}//如果是,则结束。
否则{
//塞佩因瓦利多。
limpa_formulário_cep();
警报(“投资丽都的格式”);
}
}//如果是,则结束。
否则{
//cep sem valor,林帕福尔马里奥。
limpa_formulário_cep();
}
});
});
清除页面上的bug时,我收到以下异常

jquery.min.js?ver=5.2.3:2 jQuery.Deferred exception: $(...).live is not a function TypeError: $(...).live is not a function
    at HTMLDocument.<anonymous> (https://example.com/js/main.js:177:28)
    at e (https://example.com/js/jquery.min.js?ver=5.2.3:2:29453)
    at t (https://example.com/js/jquery.min.js?ver=5.2.3:2:29755) undefined
k.Deferred.exceptionHook @ jquery.min.js?ver=5.2.3:2
jquery.min.js?ver=5.2.3:2 jQuery.Deferred exception: $(...).mask is not a function TypeError: $(...).mask is not a function
    at HTMLDocument.<anonymous> (https://example.com/cadastrar/:699:33)
    at e (https://example.com/js/jquery.min.js?ver=5.2.3:2:29453)
    at t (https://example.com/js/jquery.min.js?ver=5.2.3:2:29755) undefined
k.Deferred.exceptionHook @ jquery.min.js?ver=5.2.3:2
jquery.min.js?ver=5.2.3:2 Uncaught TypeError: $(...).live is not a function
    at HTMLDocument.<anonymous> (main.js:177)
    at e (jquery.min.js?ver=5.2.3:2)
    at t (jquery.min.js?ver=5.2.3:2)
jquery.min.js?ver=5.2.3:2 Uncaught TypeError: $(...).mask is not a function
    at HTMLDocument.<anonymous> ((index):699)
    at e (jquery.min.js?ver=5.2.3:2)
    at t (jquery.min.js?ver=5.2.3:2)
jquery.min.js?ver=5.2.3:2 jquery。延迟异常:$(…)。live不是函数类型错误:$(…)。live不是函数
在HTMLDocument(https://example.com/js/main.js:177:28)
在e(https://example.com/js/jquery.min.js?ver=5.2.3:2:29453)
at t(https://example.com/js/jquery.min.js?ver=5.2.3:2:29755)未定义
k、 Deferred.exceptionHook@jquery.min.js?ver=5.2.3:2
jquery.min.js?ver=5.2.3:2 jquery.延迟异常:$(…)。掩码不是函数类型错误:$(…)。掩码不是函数
在HTMLDocument(https://example.com/cadastrar/:699:33)
在e(https://example.com/js/jquery.min.js?ver=5.2.3:2:29453)
at t(https://example.com/js/jquery.min.js?ver=5.2.3:2:29755)未定义
k、 Deferred.exceptionHook@jquery.min.js?ver=5.2.3:2
jquery.min.js?ver=5.2.3:2未捕获类型错误:$(…)。live不是函数
在HTMLDocument(main.js:177)
在e处(jquery.min.js?ver=5.2.3:2)
在t(jquery.min.js?ver=5.2.3:2)
jquery.min.js?ver=5.2.3:2未捕获类型错误:$(…)。掩码不是函数
位于HTMLDocument。((索引):699)
在e处(jquery.min.js?ver=5.2.3:2)
在t(jquery.min.js?ver=5.2.3:2)

首先,我认为您不需要再次注册jquery,因为它是全局注册的。其次,请参见:您需要加载
jquery
,然后
maskedinput
-而不是相反-例如WordPress在安全模式下使用jquery,因此您应该使用
jquery
。例如
jquery(“#reg_billing_address_1”).val(“”;
@JaromandaX
jquery.min.js?ver=5.2.3:2 jQuery.Deferred exception: $(...).live is not a function TypeError: $(...).live is not a function
    at HTMLDocument.<anonymous> (https://example.com/js/main.js:177:28)
    at e (https://example.com/js/jquery.min.js?ver=5.2.3:2:29453)
    at t (https://example.com/js/jquery.min.js?ver=5.2.3:2:29755) undefined
k.Deferred.exceptionHook @ jquery.min.js?ver=5.2.3:2
jquery.min.js?ver=5.2.3:2 jQuery.Deferred exception: $(...).mask is not a function TypeError: $(...).mask is not a function
    at HTMLDocument.<anonymous> (https://example.com/cadastrar/:699:33)
    at e (https://example.com/js/jquery.min.js?ver=5.2.3:2:29453)
    at t (https://example.com/js/jquery.min.js?ver=5.2.3:2:29755) undefined
k.Deferred.exceptionHook @ jquery.min.js?ver=5.2.3:2
jquery.min.js?ver=5.2.3:2 Uncaught TypeError: $(...).live is not a function
    at HTMLDocument.<anonymous> (main.js:177)
    at e (jquery.min.js?ver=5.2.3:2)
    at t (jquery.min.js?ver=5.2.3:2)
jquery.min.js?ver=5.2.3:2 Uncaught TypeError: $(...).mask is not a function
    at HTMLDocument.<anonymous> ((index):699)
    at e (jquery.min.js?ver=5.2.3:2)
    at t (jquery.min.js?ver=5.2.3:2)