简体   繁体   English

将Jquery与单选按钮一起使用

[英]Using Jquery with Radio buttons

I'm putting together a simple order lookup form. 我正在整理一个简单的订单查询表。 It worked well until I added radio buttons. 在添加单选按钮之前,它一直运行良好。 In old JS, i used simple function to grab the radio button value and drop it into a string. 在旧的JS中,我使用了简单的函数来获取单选按钮值并将其放入字符串中。 Jquery does it a different way. jQuery用不同的方式做到这一点。 I think I'm close to getting this working: 我认为我即将使这个工作:

What I have so far: 到目前为止,我有:

 var e = $( "input:ordernum:checked" ).val(function( index, value) { return value + " " + this.className; var groupnum= e.options[e.selectedIndex].value; }); xmlhttp.open("GET","ordersearch.php?orderid="+ordernum+"&q="+str,true); xmlhttp.send(); 

Previously, with the drop down, it used: 以前,通过下拉菜单使用:

 var e = document.getElementById("groupnum");--> var groupnum = e.options[e.selectedIndex].value; }); 

It's probably a simple fix. 这可能是一个简单的修复。 Do I need getElementbyID or getElementbyName in this instance? 在这种情况下我需要getElementbyID或getElementbyName吗?

var e = $( "input:ordernum:checked" ).val(function( index, value) {

I've no idea about a :ordernum selector in jQuery.. 我不知道jQuery中的:ordernum选择器。

If you want to select an element using id, use $('#id') in your case, 如果要使用ID选择元素,请使用$('#id')

$('#ordernum:checked')

But i don't think that's what you need ~ For creating a radio button group, give a common name to all of them. 但是我不认为这是您需要的〜要创建一个单选按钮组,请为所有按钮都使用一个通用name Then you can access the value of selected radio button in the group like 然后,您可以访问组中选定单选按钮的值,例如

$('[name="yourGroupName"]:checked').val()

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM