2010-01-22 45 views
1

我正在使用Jquery提交表单。我想在用户点击提交按钮以获得选择选项后循环显示表单。有很多不同的选择字段。选择选项使用PHP生成。点击后的jquery循环

的HTML的样品:

<select id="selectHome_1"> 
<option></option> 
</select> 

<select id="selectHome_2"> 
    <option></option> 
</select> 

<inpupt type="submit" id="update" /> 

jQuery的

$("#update").click(function() {   
    //Loop through all select fields 
    $("input[id^='selectHome_']").each(function(){ 
    //Production code will do other things   
    alert('test');//Test to see if it works... 
    }); 
}); 

,搜索ID = selectHome_不工作的代码(警告框从未示出) 。

任何想法将不胜感激。

干杯!

回答

2

使用

$("select[id^='selectHome_']") 

和测试与

alert($("select[id^='selectHome_']").length) 
+0

提交后注意..纠正,thx。 :) – parserr 2010-01-22 21:58:31

+0

+1非常好。现在好多了:)谢谢你以这种好的方式处理纠错。 – Sampson 2010-01-22 22:00:40

+1

感谢您通过检查长度进行测试的提示。 – Matt 2010-01-22 22:02:24