简体   繁体   English

如何显示所选按钮的值?

[英]How to can i display a value of a selected button?

The following code creates a Buttons, with CSS when one of the button is clicked it changes color, each button created has its own value. 以下代码创建了一个Buttons,当单击其中一个按钮时,它会使用CSS更改颜色,创建的每个按钮都有其自己的值。 So i want to display a VALUE of a selected button if clicked on my HTML page how can manage that? 所以我想显示一个选定按钮的值,如果单击我的HTML页面,该如何管理呢?

function createButtons(tbID, tbClass, tbType, tbValue, onClick) {
    return '\n<input '
            + (tbID ? ' id=\'' + tbID + '\'' : '')
            + (tbClass ? ' class=\'' + tbClass + '\'' : '')
            + (tbType ? ' type=\'' + tbType + '\'' : '')
            + (tbValue ? ' value=\'' + tbValue + '\'' : '')
            + (onClick ? ' onclick=\'toggle(this);' + onClick + '\'' : '')
            + '>';
}

function toggle(ths) {
  $(ths).toggleClass("btnColor");
   $("#tb").toggleClass("btnColorR");  
}

function DisplayButtons(cableData) {
  var newContent = '';
  $.each(cableData,
    function (i, item) {
      newContent += createButtons("tb" + item.CommonCable, null, "submit",       item.CommonCable,toggle);
  });
  $("#Categories").html(newContent);
}

$(ths).val() or $(ths).attr('val') will get you the value. $(ths).val()$(ths).attr('val')会为您带来价值。

Demo 演示版

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在按钮中显示下拉列表的选定元素? - How can I display the selected element of a dropdown list in a button? 如何显示基于选定值的搜索表单 - How can I display a search form based on a selected value 如何在输入文本框中显示选定的值 - how can i display selected value in input text box 如何从以下获取所选按钮的当前值? - How can I get current Value of Selected button from the following? 如果我单击选择按钮并在文本框中传递其值,如何获得所选单选按钮的值? - how can i get the value of selected radio button if i click the select button and pass its value in a textbox? 如何通过单击按钮显示div的值? - How can I display value of a div with a button click? 如何根据 php 中 combobox 中的选定值在数据库中的文本框中显示该值? - How can I display value in textbox from database that value based on selected value from combobox in php? 一个按钮如何根据选择的单选按钮显示不同的结果 - How can a button display different results depending on radio button selected 当存储的值=“ on”时,如何在启动时将html单选按钮显示为选中状态? - How do I make an html radio button display as selected at launch time when the stored value=“on”? 当我单击带有数据的按钮时,我该如何执行此操作,它将使用 NextJS 在 select 选项数据上选择值? - How can I do this when I clicked button with data it will selected value on select option data with NextJS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM