5
我有一个来自客户端的任务来纠正一个页面,我发现jQuery后代选择器的行为并不像预期的那样。为什么这个jQuery选择器不起作用?
下面是HTML的excrept:
<form action="http://submit.url/subscribe.php" method="post" enctype="multipart/form-data" id="mssysform8217" class="mssysform" >
<div id="mssys-formcontainer">
<div class="formfields">
<table style="width: 100%">
<div class="formfield-item" id="formfield-item-email">
<tr>
<td class="style1"><label >E-mail címe</label></td>
<td>
<input type="text" name="email" value="">
<div class="error-container">Please fill in this field!</div>
<div style="clear: both;"></div>
</td>
</tr>
</div>
</table>
</div>
</div>
</form>
我试着用Firefox来调试它:
这工作:
console.debug($("#mssysform8217 :input[name='email']").val());
这不工作:
console.debug($("#mssysform8217 #formfield-item-email :input[name='email']").val());
不确定
但:
console.debug($("#mssysform8217 #formfield-item-email"));
[DIV#formfield项-email.formfield项]
问题提交脚本是由第三方应用程序生成的,它希望使用3级后代选择器。
为什么使用多个ID选择器(“#id”)? – Homer 2010-11-22 21:41:10
而且似乎只有一个'`从#formfield-item-email降序,所以[name]属性选择器是不必要的。 `$('#formfield-item-email input').val()`应该是你所需要的。 – stevelove 2010-11-22 21:44:26