JQuery通过2个函数传递变量

时间:2014-12-07 16:04:11

标签: javascript jquery onclick radio-button

在JQuery中,我有第一个函数 superClientChoose ,它是一个开关。加载开关内容后,您会在屏幕上看到一些输入无线电。 正如你所看到的,如果我点击一个无线电tf转到另一个函数 mainMenuManagement ,我传递变量“option”,但是......

问题是当我尝试在第二个函数中使用选项值进行警报时,我没有得到正确的值。我需要获得superMarket或客户端,但是我得到了index.html所在的URL,在我的计算机旁边...... !!

file:/// media /(...)/ index.html#

我做错了什么?

function superClientChoose(option)
{
	$("#mainMenu").hide();

	switch (option)
	{
		case "superMarket":
				$("div#mainMenu").show();

				var divContent="<br><b>Click the option to run</b><br/>";
				divContent+="<form id='superForm'> <input type='radio' name='options' id='stockEntry' onClick='mainMenuManagement("+option+")'/> Client entry";
				divContent+="<br/>";
				divContent+="<input type='radio' name='options' id='stockModify' onClick='mainMenuManagement("+option+")'/> Client modification";	
				
				divContent+="</form><br/>";

				$("#mainMenu").html(divContent);	
				break;
		case "client":
				$("div#mainMenu").show();

				var divContent="<br><b>Click the option to run</b><br/>";
				divContent+="<form id='superForm'> <input type='radio' name='options' id='clientEntry' onClick='mainMenuManagement("+option+")'/> Client entry";
				divContent+="<br/>";
				divContent+="<input type='radio' name='options' id='clientModify' onClick='mainMenuManagement("+option+")'/> Client modification";	
				divContent+="</form><br/>";

				$("#mainMenu").html(divContent);			
				break;	
		default:
			alert("Option is not correct: "+option);
			break;
	}
}

这是我遇到选项2的问题。

function mainMenuManagement(option2)
{
	var option2;
	var chosenIdSC=$('input[name=options]:checked', '#superForm').attr("id");
	
	alert(option2); //this one takes the INCORRECT value
alert("cSC: "+chosenIdSC); //this one takes the correct value
  
 // ... more and more code here...

0 个答案:

没有答案