gpt4 book ai didi

javascript - 如何在java脚本中运行并获取弹出窗口中html提交按钮的值

转载 作者:行者123 更新时间:2023-12-03 08:35:17 27 4
gpt4 key购买 nike

我在 html/wordpress 中创建了一个调查页面,然后添加了 onBeforeUnload 函数,该函数在用户关闭选项卡或单击其他页面时运行,然后如果用户单击 '留在此页面',然后将打开一个弹出窗口,其中包含静态文本和一个输入文本字段,用于获取选项卡关闭的原因。一切都运转良好。现在,如果用户在该文本框中添加一些文本并单击该弹出窗口的提交按钮,我想添加一个警报按钮。我尝试过,但单击按钮时弹出窗口未打开。有人可以帮忙吗?请

这是我的 JS

var htmlform = '<div class="ppq"><h4>There are lots of benefits in our free profile.  If you are not interested please let us know what we can do to improve.</h2><input type="text" name="ppq_text" id="ppq_text"><input type="button" class="sbmt" name="submit suggestion" id="sbmt_sg" value="submit"></div>'
var timeout;
var popuprun = true;
window.onbeforeunload = function() {
if(popuprun == true) {
var msg ="just one last question?"
timeout = setTimeout(function() {
var appendthis = ("<div class='modal-overlay js-modal-close'></div>");
$("body").append(appendthis);
$(".modal-overlay").fadeTo(500, 0.7);
$('#popup5').fadeIn($(this).data());
$('.show-full-text-popup5').html(htmlform);
}, 2000);
return msg;
}
}

此处 popuprun 是简单变量,在调查的最后一个按钮单击时将为 false。

这是我的 JS,用于单击弹出窗口中的提交按钮。

$('#sbmt_sg').click(function(){
alert('thanks');

这是点击“留在此页面”后打开的弹出窗口

Here's the popup which open after 'stay on this page' click

最佳答案

您应该将 Submit 按钮上的 click 事件委托(delegate)给 document,因为 Submit 不会当您将事件绑定(bind)到 DOM 时,它会出现在 DOM 中。

所以,

$(document).on("click", "#sbmt_sg", function(){
alert("Thanks");
});

关于javascript - 如何在java脚本中运行并获取弹出窗口中html提交按钮的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33233065/

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