js 同名数组对象的选择

                <fieldset name="onevar[]">
	                                	 <div class="field-group">
                                            <span class="required title" for="idc_id"><b><font color=red>*</font><span class="details"> 选择套餐: </span></b></span>
                                            <select name='select_tc[]' class="xxlarge" id="select_tc[]" style="margin-left:10px;" onchange="select_tc_ch(this)"  >
                                                 
                                                <option value='2|2|100'>标准开发机 (2 cpu, 2G ram, 100G disk)</option>  
												<option value='2|4|100'>高配开发机 (2 cpu, 4G ram, 100G disk)</option>
							 
                                                <option value='0'>自定义</option>  
											  
                                            </select>    
                                
                                        </div>
					<div class="field-group">
                                            <span class="required title" for="cpu_num"><b><font color=red>*</font>CPU核(个):</b></span>  
                                            <input name="cpu_num[]" type="text" class="mini-40" value="2"/>  
                                            <span class="required title" for="mem_num"><b><font color=red>*</font>内存(G):</b></span>  
                                            <input name="mem_num[]" type="text" class="mini-40" value="2"/>  
                                            <span class="required title" for="disk_num"><b><font color=red>*</font>硬盘(G):</b></span>  
                                            <input name="disk_num[]" type="text" class="mini-40" value="100"/>  
                                            <span class="required title" for="other">  <b>特殊需求:</b></span>  
                                            <input name="conf_memo[]" type="text" class="large" style="width:251px;"/>
                                        </div>
				</fieldset>

                <fieldset name="onevar[]">
	                                	 <div class="field-group">
                                            <span class="required title" for="idc_id"><b><font color=red>*</font><span class="details"> 选择套餐: </span></b></span>
                                            <select name='select_tc[]' class="xxlarge" id="select_tc[]" style="margin-left:10px;" onchange="select_tc_ch(this)"  >
                                                 
                                                <option value='2|2|100'>标准开发机 (2 cpu, 2G ram, 100G disk)</option>  
												<option value='2|4|100'>高配开发机 (2 cpu, 4G ram, 100G disk)</option>
											   
                                                <option value='0'>自定义</option>  
											  
                                            </select>    
                                
                                        </div>
					<div class="field-group">
                                            <span class="required title" for="cpu_num"><b><font color=red>*</font>CPU核(个):</b></span>  
                                            <input name="cpu_num[]" type="text" class="mini-40" value="2"/>  
                                            <span class="required title" for="mem_num"><b><font color=red>*</font>内存(G):</b></span>  
                                            <input name="mem_num[]" type="text" class="mini-40" value="2"/>  
                                            <span class="required title" for="disk_num"><b><font color=red>*</font>硬盘(G):</b></span>  
                                            <input name="disk_num[]" type="text" class="mini-40" value="100"/>  
                                            <span class="required title" for="other">  <b>特殊需求:</b></span>  
                                            <input name="conf_memo[]" type="text" class="large" style="width:251px;"/>
                                        </div>
				</fieldset>

通过选择套餐,选中同块的元素

		function select_tc_ch(selectobj)
		{
			pobj = selectobj.parentElement;//这是div group
			ppobj = pobj.parentElement;//这就是所在的onevar
			console.log(ppobj);
			
			initval = selectobj.value;    
			arr = initval.split("|");
			cpu_num="";
			mem_num="";
			disk_num="";
			if(arr.length>=3)
			{
	            cpu_num=arr[0];
	            mem_num=arr[1];
	            disk_num=arr[2];		
			 	
			} 
			//转化成jquery目标
			jselectobj =  $(ppobj);
		   //onevar旗下的cpu_num
		   obj_cpu_num = $("input[name='cpu_num[]']", jselectobj);
           obj_mem_num = $("input[name='mem_num[]']", jselectobj);
           obj_disk_num = $("input[name='disk_num[]']", jselectobj);
		   obj_cpu_num.val(cpu_num);
           obj_mem_num.val(mem_num);
           obj_disk_num.val(disk_num);
		 
		}










   

你可能感兴趣的:(js 同名数组对象的选择)