按下编辑按钮时填写输入字段
我正在寻找一种通过 jQuery/Javascript 的方法来用我从表中获取的数据填充一些输入字段。我的表格如下所示:
<tr>
<th>ticketID</th>
<th>eventID</th>
<th>name</th>
<th>price</th>
<th>priceWithinAllocation</th>
<th> </th>
</tr>
<tr >
<td class="ticketID">1</td>
<td class="eventID">1</td>
<td class="name">Sun</td>
<td class="price">300</td>
td class="priceWithinAllocation">150</td>
<td align="center"><input type="button" class="editRow" value="EDIT"/></td>
</tr>
<tr >
<td class="ticketID">2</td>
<td class="eventID">1</td>
<td class="name">Mon</td>
<td class="price">300</td>
<td class="priceWithinAllocation">150</td>
<td align="center"><input type="button" class="editRow" value="EDIT"/></td>
</tr>
我还有一个表格,我希望值出现在其中。但是,并非所有值都应该出现在那里。
<p>
<label for="">Name:</label>
<input type="text" name="name" />
</p>
<p>
<label for="">Price:</label>
<input type="text" name="price" />
</p>
<p>
<label for="">PriceWithinAllocation:</label>
<input type="text" name="priceWithinAllocation" />
因此,假设我单击第一行的“编辑”按钮,我希望 name
、price
和 pricewithinallocation
显示在我的输入字段中。但是,我认为没有办法做到这一点。我尝试了一些 jquery DOM 遍历,但效果并不理想。有人在这里看到任何解决方案吗?这可能吗?
</p>
<p>
<input type="submit" id="saveNew" value="SAVE" />
<input type="button" id="cancelNew" value="CANCEL" />
I'm looking for a way through jQuery/Javascript to fill up some input fields with data I get out of a table. The table I have looks like this:
<tr>
<th>ticketID</th>
<th>eventID</th>
<th>name</th>
<th>price</th>
<th>priceWithinAllocation</th>
<th> </th>
</tr>
<tr >
<td class="ticketID">1</td>
<td class="eventID">1</td>
<td class="name">Sun</td>
<td class="price">300</td>
td class="priceWithinAllocation">150</td>
<td align="center"><input type="button" class="editRow" value="EDIT"/></td>
</tr>
<tr >
<td class="ticketID">2</td>
<td class="eventID">1</td>
<td class="name">Mon</td>
<td class="price">300</td>
<td class="priceWithinAllocation">150</td>
<td align="center"><input type="button" class="editRow" value="EDIT"/></td>
</tr>
I also have a form which I want the values to appear in. However, not all values should appear there.
<p>
<label for="">Name:</label>
<input type="text" name="name" />
</p>
<p>
<label for="">Price:</label>
<input type="text" name="price" />
</p>
<p>
<label for="">PriceWithinAllocation:</label>
<input type="text" name="priceWithinAllocation" />
So, say I click on the EDIT button of the first row, I want the name
, price
and pricewithinallocation
to appear in my input fields. However, I see no way to do this. I tried with some jquery DOM traversal, but that didn't work out exactly. Anyone see any solution here? Is this even possible?
</p>
<p>
<input type="submit" id="saveNew" value="SAVE" />
<input type="button" id="cancelNew" value="CANCEL" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
工作示例: http://jsfiddle.net/2QVQ6/
替代方案:
Try this:
Working example: http://jsfiddle.net/2QVQ6/
Alternative:
当然有可能。
实例:http://jsfiddle.net/4tWjh/
Of course its possible.
Live example: http://jsfiddle.net/4tWjh/