2

私はこれらの入力を持っています:

<input type='radio' id='1' name='s' onclick='pieces(this.value);'  value='6'>6
<input type='radio' id='2' name='s' onclick='pieces(this.value);'  value='12'>12
<input type='radio' id='3' name='s' onclick='pieces(this.value);'  value='24'>24
<input type='radio' id='11' name='v' onclick='pieces(this.value);'  value='yes'>Yes
<input type='radio' id='12' name='v' onclick='pieces(this.value);'  value='no'>No

pieces(var1, var2)ラジオボタンがクリックされたときに、「name='s'」から var1 への値と「name='v'」から var2 への値を関数に渡したいと思います。

4

3 に答える 3

1

メソッドを使用してJavascriptメソッド自体で両方の無線入力の値を取得できます。document.getElementsByName()または、これも機能するはずです。使用
してみてくださいfunc(document.getElementsByName('s'),document.getElementsByName('v'))

以下のコードが役立つはずです、

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="js1/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    alert('Ok');
    $('#btn').click(function(){
        var r1=$('input:radio[name=s]').val();
        var r2=$('input:radio[name=v]').val();
        show(r1,r2);
    });
});

function show(r1,r2){
    alert(r1);
    alert(r2);
}
</script>
</head>
<body>
<input type='radio' id='1' name='s' onclick='pieces(this.value);'  value='6'>6
<input type='radio' id='2' name='s' onclick='pieces(this.value);'  value='12'>12
<input type='radio' id='3' name='s' onclick='pieces(this.value);'  value='24'>24


<input type='radio' id='11' name='v' onclick='pieces(this.value);'  value='yes'>Yes
<input type='radio' id='12' name='v' onclick='pieces(this.value);'  value='no'>No

<button id="btn">Submit</button>
</body>
</html>
于 2012-06-30T06:01:02.893 に答える
1

次のさまざまな方法で引数を渡すことができます。

function antguider(name, url){
    alert("Name = "+name+" URL = "+url);
}

HTML 部分

<input type="button" onclick=antguider('AntGuider','http://antguider.blogspot.com') value="Click Without Quotation" />
<input type="button" onclick="antguider('AntGuider','http://antguider.blogspot.com')" value="Click With Quotation" />
<input type="button" onclick="antguider(12345,'http://antguider.blogspot.com')" value="No Quotation Needed For Button" />
于 2012-06-30T06:08:22.807 に答える
0

2 つの入力の場合、これは JQuery で簡単に実行できます。

va1=$("input[name=s]").val();
va2=$("input[name=v]").val();

次に、目的の関数を呼び出して、値をパラメーターとして渡します。

func(va1,va2);
于 2012-06-30T05:52:56.047 に答える