javascript - jQuery 开关按钮开/关应设置不同的数据状态和 Onclick 功能

标签 javascript jquery html switch-statement toggle

仍在学习 jQuery,并将感谢任何帮助。

我目前正在使用这个 jQuery Switchbutton https://github.com/olance/jQuery-switchButton 它使用复选框作为输入类型,并创建带标签的跨度标签。 我怎么说我希望 on_label 具有 data-status="accept"和 off_label data-status="decline"?

HTML: <input type="checkbox" id="accept-offer"/>

JS: $("input#accept-offer").switchButton({ on_label: "Accept", off_label: "Ignore"<br/> });

谢谢!!

最佳答案

你可以尝试这样做:

$('.switch-button-label.on').data('status','accept');
$('.switch-button-label.off').data('status','decline');

或者:

$('.switch-button-label.on').attr('data-status','accept');
$('.switch-button-label.off').attr('data-status','decline');

关于javascript - jQuery 开关按钮开/关应设置不同的数据状态和 Onclick 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21231063/

相关文章:

javascript - 如何在eclipse中调试jsp和javascript文件?

javascript - 无法在 Internet Explorer 9 的文本框中键入

html - 在将实际图像加载到框架之前,如何根据 CSS 使浏览器缩放图像框架?

html - 在伪列表项之前垂直对齐

javascript - 如何将值从一个表单组实时传递到另一个表单组作为响应式(Reactive)表单中的双向数据绑定(bind)?

javascript - 如何在 MS Dynamics CRM 4.0 中将控件的数据值设置为数字?

javascript - 在 Ajax 接触加载后切换 Bootstrap 模式

jquery - 将 JSON 转换为 TR 和 TD

javascript - 每 5 秒刷新一次 JSON 填充图表的内容

html - 为什么一些一次性使用的元素在 CSS 中是 Class 而不是 ID?