javascript - 检索按钮 jquery 的值
问题描述
我有这个:
<div class="cable-config">
<span>Select Entries</span>
<div class="cable-choose">
<button id="Home" value="5.00">50 Entries<br>$5.00</button>
<button value="10.00">100 Entries<br>$10.00</button>
<button>250 Entries<br>$25.00</button>
<button>500 Entries<br>$50.00</button>
</div>
<p>By entering, you agree to our Terms of Service, Official Rules, and Privacy Policy.</p>
</div>
</div>
<script>
var buttonValue = ""
$('button').on('click', function(){
$('button').removeClass('active_button');
$(this).addClass('active_button');
// var fired_button = $(this).val();
// alert(fired_button);
});
//Home button active on page load
$(document).ready(function(){
$('#Home').addClass('active_button');
});
单击按钮时它会做什么,将其设置class
为active_button
.
现在我要做的是active_button
在单击新按钮时获取类的值。如您所见,我尝试检索 的值active_button
,但它返回undefined.
我做错了什么?
function myfunction() {
var valueOfButton = $('active_button').val();
console.log(valueOfButton);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="cable-config">
<span>Select Entries</span>
<div class="cable-choose">
<button id="Home" value="5.00">50 Entries<br>$5.00</button>
<button value="10.00">100 Entries<br>$10.00</button>
<button>250 Entries<br>$25.00</button>
<button>500 Entries<br>$50.00</button>
</div>
<p>By entering, you agree to our Terms of Service, Official Rules, and Privacy Policy.</p>
</div>
<div class="product-price">
<button onclick="myfunction()" class="cart-btn">Continue To Payment</button>
</div>
解决方案
推荐阅读
- angular - Ionic - 在多个页面中工作的注销功能
- python - 如何在按属性分组时查询对象集合
- docker - Hadoop 与 docker 运行“hdfs dfs -put”错误
- backup - 恢复centos“/”分区回来的问题
- sql - 交叉连接表以查看一个表中的哪些合作伙伴有另一个表中的报告
- python - 在测试和训练数据集中使用基于时间的拆分来拆分数据
- python - 在辅助监视器中打开 Python CEF 应用程序
- python - 如何解释和调查不平衡数据中的完美准确度、精确度、召回率、F1 和 AUC(我不信任)
- elasticsearch - 用于缓存和搜索产品的弹性搜索?
- angular - ng build --prod 时使用 ngx-hm-carousel 模块出错