Asp.net中的RadioButtonCheckBox控件在生成html代码时都会相应的生产两个html控件, RadioButton会生成radio+label, CheckBox会生成checkbox+label,它们相应的显示文字都会显示到label控件里,并通过for属性关联控件

     如果要通过js找到RadioButtonCheckBox控件显示的文字(text属性)可以使用下面的方法:

       

function getLabelForText(radioId) //radioId  控件ID
{
    
var radioLabels = document.getElementsByTagName("label");  //所有label控件
    var radioText;
    
for (var j = 0; j < radioLabels.length; j++)
    {
        
if (radioId == radioLabels[j].getAttribute("for"))  //找到label控件关联的radio或checkbox控件
        {
            radioText 
= radioLabels[j].innerText;
            
break;
        }
    }
    
return radioText;   //返回text属性值
}

相关文章:

  • 2021-05-31
  • 2022-02-15
  • 2022-12-23
  • 2022-01-23
  • 2021-09-11
  • 2021-07-25
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案