gpt4 book ai didi

javascript - JQuery 函数根据隐藏的 HTML 输入元素的值显示元素

转载 作者:行者123 更新时间:2023-11-28 09:08:33 25 4
gpt4 key购买 nike

作为我的回答的序言,对于 JQUERY,我绝对是个新手。

我正在尝试创建一个 DOM 就绪函数,它采用隐藏的 HTML 输入字段的值,如果该值是 ...(某物),则显示某个 <div>类(class)。

这是我的代码:

JS - 已更新

   $(document).ready(function(){

var money = 19.95;

/* not sure if this is written correctly, but this is supposed to
check whether the hidden input element value is equal to var money */

if ($("input[id='VAT_shipping'][type='hidden']").val() == money ) {

$("#ac-wrapper").show();
$("#popup").show();

};

// hide popup when user clicks on close button
$(".close-btn").click(function(){
$("#ac-wrapper").hide();
// hide
});

// hides the popup if user clicks anywhere outside the container
$("#ac-wrapper").click(function(){
$("#popup").hide();
})

// prevents the overlay from closing if user clicks inside the popup overlay
$("#ac-wrapper.").click(function(e) {
e.preventDefault();
var $this = $(this);
var horizontalPadding = 30;
var verticalPadding = 30;
});
});

HTML

<input type="hidden" id="VAT_shipping" value="<? print $shipping; ?>" />

<div id="ac-wrapper">
<div id="popup">
<center>
<p>
<strong> You have selected World Free Tax Zone - £19.95 for shipping. </strong>

We will automatically remove the VAT - 20% from your order.

Please click close to return to review your order.

</p>
<button class="close-btn">Close</button>
</center>
</div>
</div>

CSS

#ac-wrapper {
display:none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255,255,255,.6);
z-index: 1001;
}
#popup {

width: 555px;
height: 375px;
background: #FFFFFF;
border: 5px solid #000;
border-radius: 25px;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
box-shadow: #64686e 0px 0px 3px 3px;
-moz-box-shadow: #64686e 0px 0px 3px 3px;
-webkit-box-shadow: #64686e 0px 0px 3px 3px;
position: relative;
top: 200px; left: 375px;
font-size: 16px;
font-family: 'Oxygen', sans-serif;
text-align: center
}

.close-btn {
cursor: pointer;
font-family:Tahoma, Geneva, sans-serif;
border: 1px solid #000000;
color: #ffffff;
background-color: #AC9E33;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
text-shadow: 0 1px 1px #000000;
font: bold 11px Sans-Serif;
text-transform:none;
padding: 7px 12px;
margin:0;
background-image: -webkit-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: -moz-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: -o-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: -ms-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: linear-gradient(transparent, rgba(0, 0, 0, 0.2));
-webkit-transition: background-color 0.3s;
-moz-transition: background-color 0.3s;
-o-transition: background-color 0.3s;
-ms-transition: background-color 0.3s;
transition: background-color 0.3s;
}
.close-btn:hover {
font-family:Tahoma, Geneva, sans-serif;
border: 1px solid #000000;
color: #ffffff;
background-color: #515280;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
text-shadow: 0 1px 1px #000000;
font: bold 11px Sans-Serif;
text-transform:none;
padding: 7px 12px;
margin:0;
background-image: -webkit-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: -moz-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: -o-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: -ms-linear-gradient(transparent, rgba(0, 0, 0, 0.2));
background-image: linear-gradient(transparent, rgba(0, 0, 0, 0.2));
-webkit-transition: background-color 0.3s;
-moz-transition: background-color 0.3s;
-o-transition: background-color 0.3s;
-ms-transition: background-color 0.3s;
transition: background-color 0.3s;
}

因此 jQuery 函数检查 shipping 的值输入字段,如果它等于 var money = 19.95然后是 ac-wrapper并嵌套 popup显示。然后,客户端可以使用“close-btn”或单击元素外部来关闭此窗口。

请有人解释一下如何做到这一点。

最佳答案

你的第一个问题是

if ($("input[name='shipping']").val(money); )  {

应该是

if ($("input[id='shipping']").val() == money )  {

    if ($("input[id='shipping'][type='hidden']").val() == money )  {

关于javascript - JQuery 函数根据隐藏的 HTML 输入元素的值显示元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26589221/

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