gpt4 book ai didi

javascript - jquery.click(function) WordPress 小部件

转载 作者:行者123 更新时间:2023-12-03 11:36:42 25 4
gpt4 key购买 nike

当我在 header 中使用此函数时,它工作正常,但当我在小部件中使用它时,什么也没有发生

$("#myID").click(function(){
var name = $("#name").val();
var phone = $("#phone").val();
console.log(name +" "+ phone);
if(name.length > 1 && phone.length > 7){
$.ajax({
url: 'my_url',
type: 'post',
data: {'name': name,
'number': phone},
success: function(data){
$(".header-bg-title").html('thanks');
$("span.white").hide();
},
error: function(response){
alert('error');
}
});
} else {
$("p#onerror").html('write your name & number');
}

});

html

<div class="col-xs-12">
<h2>text</h2>
<p id="onerror">My text</p>
<p><input id="name" class="form-control" type="text" placeholder="Name" /></p>
<p><input id="phone" class="form-control" type="text" placeholder="Phone" /></p>
<p><button id="myID" class="btn btn-warning btn-block btn-lg" type="button">Send</button></p>
</div>

有人有建议吗?

最佳答案

据我所知,.click 在执行时会附加到该项目,如果该项目不存在,则在小部件的情况下它将不会附加。我可能是错的,试试这个,看看它是否有效。

$('body').on('click', '#myID', function() {
...
});

关于javascript - jquery.click(function) WordPress 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26466570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com