相关疑难解决方法(0)

jQuery获取所选单选按钮的值

问题陈述很简单.我需要查看用户是否从广播组中选择了一个单选按钮.组中的每个单选按钮共享相同的ID.

问题是我无法控制表单的生成方式.以下是单选按钮控件代码的示例代码:

<input type="radio" name='s_2_1_6_0' value='Mail copy to my bill to address' id = "InvCopyRadio" onchange = 'SWESubmitForm(document.SWEForm2_0,s_4,"","1-DPWJJF")' style="height:20;width:25" tabindex=1997 >
Run Code Online (Sandbox Code Playgroud)

除此之外,当选择单选按钮时,它不会向控件添加"已选中"属性,只是选中 了文本(我猜测只检查了没有值的属性).以下是所选无线电控制的外观

<input type="radio" checked name='s_2_1_6_0' value='Mail copy to my bill to address' id = "InvCopyRadio" onchange = 'SWESubmitForm(document.SWEForm2_0,s_4,"","1-DPWJJF")' style="height:20;width:25" tabindex=1997 >
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我使用jQuery代码,可以帮助我获得已检查单选按钮的值吗?

jquery siebel radio-button

507
推荐指数
20
解决办法
106万
查看次数

在jQuery中,当它们都具有相同的名称时,如何获得单选按钮的值?

这是我的代码:

<table>
   <tr>
      <td>Sales Promotion</td>
      <td><input type="radio" name="q12_3" value="1">1</td>
      <td><input type="radio" name="q12_3" value="2">2</td>
      <td><input type="radio" name="q12_3" value="3">3</td>
      <td><input type="radio" name="q12_3" value="4">4</td>
      <td><input type="radio" name="q12_3" value="5">5</td>
   </tr>
</table>
<button id="submit">submit</button>
Run Code Online (Sandbox Code Playgroud)

这是JS:

$(function(){
    $("#submit").click(function(){      
        alert($('input[name=q12_3]').val());
    });
 });
Run Code Online (Sandbox Code Playgroud)

这是JSFIDDLE!每次我点击按钮它都会返回1.为什么?谁能帮我?

javascript jquery

108
推荐指数
4
解决办法
27万
查看次数

获取单选按钮组的值

我正在尝试使用下面给出的jQuery语法获取两个单选按钮组的值.当运行以下代码时,我从第一个单选按钮组中选择两次,而不是获取每个组的值.

我在做一些明显不对的事吗?谢谢你的帮助 :)

<a href='#' id='check_var'>Check values</a><br/><br/>
<script>
  $('a#check_var').click(function() {
    alert($("input:radio['name=r']:checked").val()+ ' ' +
          $("input:radio['name=s']:checked").val());
  });
</script>
Group 1<br/>
<input type="radio"  name="r" value="radio1"/> radio1
<input type="radio"  name="r" value="radio2"/> radio2
<br/><br/>
Group 2<br/>
<input type="radio"  name="s" value="radio3"/> radio3
<input type="radio"  name="s" value="radio4"/> radio4
Run Code Online (Sandbox Code Playgroud)

jquery radio-button

69
推荐指数
1
解决办法
11万
查看次数

在ASP.NET RadioButtonList ListItem上设置CSS类

有没有办法在单选按钮列表中的输入项上设置CSS类?我想在jQuery中按类引用这些表单值.

给定一个ASP.NET RadioButtonList,在ListItems上设置类:

 <asp:RadioButtonList ID="RadioButtonList" runat="server">
      <asp:ListItem class="myClass" Text="Yes" Value="1" />
      <asp:ListItem class="myClass" Text="No" Value="0" />
 </asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)

将呈现为:

 <span id="RadioButtonList" class="radioButtonListField myClass">
     <span class="myClass">
          <input id="RadioButtonList_0" type="radio" value="1" 
               name="RadioButtonList"/>
          <label for="RadioButtonList_0">Yes</label>
     </span>
     <span class="myClass">
          <input id="RadioButtonList_1" type="radio" value="0" 
               name="RadioButtonList"/>
          <label for="RadioButtonList_1">No</label>
     </span>
 </span>
Run Code Online (Sandbox Code Playgroud)

不幸的是,"myClass"类被添加到<span>包含单选按钮项而不是它<input>自身.我怎么能让它看起来像这样:

 <span id="RadioButtonList" class="radioButtonListField myClass">
     <span>
          <input id="RadioButtonList_0" class="myClass" type="radio" value="1" 
               name="RadioButtonList"/>
          <label for="RadioButtonList_0">Yes</label>
     </span>
     <span>
          <input id="RadioButtonList_1" class="myClass" type="radio" value="0" 
               name="RadioButtonList"/>
          <label for="RadioButtonList_1">No</label>
     </span>
 </span>
Run Code Online (Sandbox Code Playgroud)

(这甚至没有涉及将类添加到动态绑定RadioButtonLists的问题.)

css asp.net radiobuttonlist listitem

24
推荐指数
2
解决办法
4万
查看次数

iCheck库:所选单选按钮的值

jsFiddle 在这里.

我是Javascript的新手,无法在iCheck页面上关注文档.我已经按照这里看起来非常相关的StackOverflow问题的答案,但是无法获得警告以弹出显示我选择的值.有人能指出我正确的方向吗?

HTML

<p>Are you sure you want to have your details removed from our marketing list?</p>
<div id="unsubscribe_radio">
    <ul>
        <li>
            <input type="radio" name="iCheck" value="yes">
            <label>Yes</label>
        </li>
        <li>
            <input type="radio" name="iCheck" value="no">
            <label>No</label>
        </li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript

$(document).ready(function () {
  $('input').iCheck({
     radioClass: 'iradio_flat-orange'
  });
  $("input:radio[name=iCheck]").click(function () {
     var value = $(this).val();
     alert("You clicked " + value);
  });
 });
Run Code Online (Sandbox Code Playgroud)

javascript jquery icheck

14
推荐指数
4
解决办法
4万
查看次数

按名称属性获取textarea

如果我想通过ID获取字段数据,我将使用: var contentText = $("#contentText").val();

如何按字段名称获取字段数据?

即: <textarea name="contentText"></textarea>

javascript jquery

-1
推荐指数
1
解决办法
4341
查看次数