gpt4 book ai didi

javascript - jQuery dblclick() 问题?

转载 作者:行者123 更新时间:2023-11-27 22:56:48 25 4
gpt4 key购买 nike

我有 2 个输入字段

a) 电子邮件和
b) 私有(private)邮箱

我想在用户双击电子邮件字段时显示警报消息 1,在用户双击 private_email 字段时显示警报消息 2。因此,我使用以下 jQuery 代码,但它在警报消息中仅显示 1:

jQuery 代码:

$(document).ready(function(){
$("input#email, input#email_private").dblclick(function(){
var email = $("input#email").val();
var private_email = $("input#email_private").val();
var cdid = $("#cdid_hidden").val();
var cid=$('#cdid_hidden').val();

if(email) {
alert(1);
window.open('mailto:<?php echo $res['email']; ?>?subject=', '_self');
} else {
window.open('mailto:<?php echo $res['email_private']; ?>?subject=', '_self');
alert(2);

}

var url = "response.php?confirmEmail=confirm&cdid="+cdid;
$.get(url);
getDetails(cid);

});
});

最佳答案

只需检查被单击的元素是否is()其中之一,并相应执行。

$(document).ready(function(){
$("input#email, input#email_private").dblclick(function(){
var email = $("input#email");
var emailVal = email.val();
var private_email = $("input#email_private").val();
var cdid = $("#cdid_hidden").val();
var cid=$('#cdid_hidden').val();

if($(this).is(email)) {
alert(1);
window.open('mailto:<?php echo $res['emailVal']; ?>?subject=', '_self');
} else {
window.open('mailto:<?php echo $res['email_private']; ?>?subject=', '_self');
alert(2);

}

var url = "response.php?confirmEmail=confirm&cdid="+cdid;
$.get(url);
getDetails(cid);

});
});

关于javascript - jQuery dblclick() 问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37520582/

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