gpt4 book ai didi

javascript - 更改类 IF 下拉列表和 H2 内容与 Animate.css 匹配某些条件

转载 作者:行者123 更新时间:2023-11-28 04:10:01 25 4
gpt4 key购买 nike

如果满足两种不同的场景,希望使用 jQuery 添加一个类

1) The dropdown equals acting or backstage

2) The membership fields contains "Non-member"

if both these are met I wish to pulse(animate) the Upgrade button using the added Animate.css class.

我有一个函数的几个部分,只是在将它们拼凑起来工作时遇到了一些麻烦:

($(this).val() == 'Acting' || $(this).val() == 'Backstage')

$("#member_status").each(function() {
var value = $(this).text();
if(value === 'Non-member'){
$("#upgrade_member").css('display','block');
}
});

  <head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">
</head>

<body>
<h1 id="member_welcome">Welcome to our membership site</h1>
<h2 id="member_status">Non-member</h2>

<select class="regular-text" name="interest" id="interest">
<option value="not specified">Not Specified</option>
<option value="Watching">Watching</option>
<option value="Acting">Acting</option>
<option value="Backstage">Backstage</option>
<option value="Supplier">Supplier</option>
</select>

<div style="margin-top:20px">
<button id="upgrade_member">Upgrade Membership</button>
</div>

<div id="example" class="animated infinite bounce" style="margin-top:100px;">EXAMPLE</div>
</body>

</html>

Here is the Plunker

最佳答案

我会这样做:

$("#interest").change(function() {
var membership = $("#member_status").text().toLowerCase().includes("non-member");
var interest = $("#interest").val().toLowerCase();
if (membership && (interest == "acting" || interest == "backstage")) {
$("#upgrade_member").addClass("animated infinite pulse");
} else {
$("#upgrade_member").removeClass("animated infinite pulse");
}
});

$(document).ready(function(){
$("#interest").change();
});

Here is the JSFiddle demo

关于javascript - 更改类 IF 下拉列表和 H2 内容与 Animate.css 匹配某些条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42760380/

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