Javascript 如何在没有';这个';?
我有一个表格看起来像这样:Javascript 如何在没有';这个';?,javascript,jquery,Javascript,Jquery,我有一个表格看起来像这样: <div> <div class="contact"> <h1>Person's name</h1> <!-- more stuff goes here --> <form method="post" action="myurl"> <input type="submit" value="go" />
<div>
<div class="contact">
<h1>Person's name</h1>
<!-- more stuff goes here -->
<form method="post" action="myurl">
<input type="submit" value="go" />
</form>
</div>
<div class="contact">
<h1>Another name</h1>
<!-- more stuff goes here -->
<form method="post" action="myOtherUrl">
<input type="submit" value="go" />
</form>
</div>
</div>
不幸的是,本例中的this
运算符引用了正在提交的表单。我想我可能遗漏了一些简单的东西,但我的头脑在这件事上却一片空白。保持简单:
var parent = $(this).closest('div.contact'); // get containing DIV
var i = $('div.contact').index(parent); // get index relative to the rest
保持简单:
var parent = $(this).closest('div.contact'); // get containing DIV
var i = $('div.contact').index(parent); // get index relative to the rest
我只想引用我自己的话:“我想我可能遗漏了一些简单的东西……”谢谢。不用担心。我知道离问题太近是什么感觉。我只想引用我自己的话:“我想可能有一些简单的东西我遗漏了……”谢谢。不用担心。我知道离问题太近是什么感觉。
var i = $(this).parents('.contact:first').prevAll('.contract').length