如何在onclick上获得另一个div中第一个Div元素的值? [英] How can I get the value of 1st Div element present inside another div on onclick?
本文介绍了如何在onclick上获得另一个div中第一个Div元素的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<div id="display_flat_details">
<div class="flat_no" id="104"><h3>104</h3></div>
<div class="flat_area" id="1650 Sq.ft"><h3>1650 Sq.ft</h3></div>
<div class="flat_price" id="75,34,544"><h3>75,34,544</h3></div>
<div class="flat_details"><input type="button" class="view_flat_details_3bhk" value="View details"></div>
</div>
<div id="display_flat_details">
<div class="flat_no" id="104"><h3>104</h3></div>
<div class="flat_area" id="1650 Sq.ft"><h3>1650 Sq.ft</h3></div>
<div class="flat_price" id="75,34,544"><h3>75,34,544</h3></div>
<div class="flat_details"><input type="button" class="view_flat_details_3bhk" value="View details"></div>
</div>
当我点击按钮时,我应该得到相应行的flat_no值?我该怎么办?得到这个?请帮帮我!
When I click on the button, I should get the value of flat_no of that respective row?How can I get this?Please help me out!
推荐答案
如果你能改变你的标记稍微会更正确 - 你不应该在id属性中使用数值..因为这个id是你应该真正使用的元数据data-id =104
如果您不想更改为data-id,只需将下面的JS从.attr('data-id')
更改为.attr('id')
If you can change your markup slightly it will be more "correct" - you should not use numeric values in the id attribute.. as this id is meta data you should really use data-id="104"
If you don't want to change to data-id, simply change the JS below from.attr('data-id')
to.attr('id')
<div id="display_flat_details">
<div class="flat_no" id="104"><h3>104</h3></div>
<div class="flat_area" id="1650 Sq.ft"><h3>1650 Sq.ft</h3></div>
<div class="flat_price" id="75,34,544"><h3>75,34,544</h3></div>
<div class="flat_details"><input type="button" class="view_flat_details_3bhk" value="View details"></div>
</div>
和JS
And the JS
( document )。ready( function (e){
(document).ready(function(e){
(' 。flat_details input')。on(' 点击',功能(e){
var flat_no =
('.flat_details input').on('click',function(e){ var flat_no =
这篇关于如何在onclick上获得另一个div中第一个Div元素的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文