gpt4 book ai didi

javascript - 无法在点击事件时触发弹出框

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

我正在将 ajax 请求的结果打包到 div 上并附加到页面中的主 div 中。因此,如果结果数组返回空,我想提醒用户,说没有找到结果,并提供一个链接供他们点击。当他们单击时,会弹出一个包含按类别划分的产品的弹出框。这里需要注意的重要一点是,产品是通过 php 和 ajax 脚本导出的。

所以当我使用 onclick 事件或直接使用时,什么也没有发生!但如果我调用空或 HTML 弹出窗口,它就会起作用。如果我在页面加载或 ajax 成功函数中触发它,包含弹出窗口的相同 php 脚本也将起作用。所以我不明白为什么只有点击它不起作用?

这是我想在“点击”事件上触发的弹出窗口

 <section id="browse-search-popup" class="mfp-hide white-popup">
<h1>Browse Courses</h1>
<a href="">Can't find what you're looking for? Tell us here!</a>
<h2>First, pick a learning Zone:</h2>
<div class="row">
<div class="small-12 medium-8 large-8 medium-centered large-centered columns">
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<?php
$tutor = new register();
$data = $tutor->get_maincat();
$i=0;
foreach($data as $k=>$v)
{
$i++;
?>

<li><div class="mainCat_<?php echo $i;?>" id="<?php echo $v['main_cat_id'];?>"><?php echo $v['main_cat_name'];?></div></li>

<?php
}
?>
</ul>
</div>
</div>


<h2>Then, pick a field:</h2>
<div class="row">
<div class="small-12 medium-12 large-12 columns" id="cat">
</div>
</div>

<h2>Finally, choose your Course:</h2>
<div class="row">
<div class="small-12 medium-12 large-12 columns" class="choosen_subjects">
</div>
</div>

<div class="row">
<div class="small-12 medium-12 large-12 columns" id="sub">
</div>
</div>
<input type="submit" id="done" value="Done">
</section>

Ajax 请求

$("#search_tutor").submit(function() {
var data = {
"action": "test"
};
var subject = $("#subject").val();
data = $(this).serialize() + "&" + $.param(data);

$.ajax({
type: "POST",
dataType: "json",
url: "/fetch_tutor.php", //Relative or absolute path to response.php file
data: data,
success: function(data) {
$("#contents img.loading").remove();
var sizy = data.length;
if(sizy ==0) {
console.log("sorry, cannot locate");
$(".simply-popup-link").trigger("click");
$("#simply-popup").empty();

//This is where I want to trigger the on click
$("#simply-popup").append("Unable to locate the subject you entered, please <a href='#' onclick='browse("+sizy+")' class='yellow'>Browse</a>");

}
console.log("size= "+data.length);
var j=0;
for (i = 0; i < data.length; i++) {
........................
......................

浏览功能:

function browse(param) {
//this would work
/* $(".simply-popup-link").trigger("click");
$("#simply-popup").empty();
$("#simply-popup").append("test only"); */

// but not this
$(".browse-search-popup-link").trigger("click");
}

我尝试将页面加载到空弹出框($("#simply-popup"))中,如下所示,但也不起作用:

 $("#simply-popup").load('search/browse.php');

最佳答案

改变

$("#simply-popup").append("Unable to locate the subject you entered, please <a href='#'  onclick='browse("+sizy+")' class='yellow'>Browse</a>");

$("#simply-popup").append("Unable to locate the subject you entered, please <a href='#' class='yellow browse'>Browse</a>");

为此编写单独的代码

$('body').on('click', '.browse', function() {
$('.browse-search-popup-link').click();
});

关于javascript - 无法在点击事件时触发弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33210682/

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