简体   繁体   English

从div中的ap标签中选择一个值

[英]Selecting a value from a p tag within a div

I am creating a list of records that is contained within divs, I want to get the value of the contents within ap tag that is within the div clicked. 我正在创建div中包含的记录的列表,我想获取div内单击的ap标记内的内容的值。 How do I reference to the p tag and its value with a .click function, using some jquery? 如何通过jquery使用.click函数引用p标签及其值?

What I have 我有的

<div class="result_box">
     <p class="result_text" id="res_id">id# 0000000</p>
     <p class="result_text" id="res_mail">resume@resume.com</p>
     <p class="result_text" id="res_complete">Active</p>
     <p class="result_text" id="res_date">11/11/11</p>
</div>

Javascript 使用Javascript

var record       = $(".result_box"); //Fields wrapper

 $(record).click(function(e){ //on add input button click
    //e.preventDefault();
    var record_id = //whatever value is within <p id="res_id">

    alert('button_clicked');
});

Additional info if needed, the class "result_box" is the same throughout, but I just want the value with that specific result box. 如果需要其他信息,则类“ result_box”在整个过程中都是相同的,但我只需要具有特定结果框的值。

Within the div clicked, use:- 在单击的div内,使用:-

var record_id = $(this).children('#res_id').text();

Though, as an Id should be unique, you could just do:- 不过,由于ID应该是唯一的,因此您可以执行以下操作:-

var record_id = $('#res_id').text();

If you are using multiple #res_id , then change them to classes .res_id and do:- 如果您使用多个#res_id ,则将它们更改为类.res_id并执行以下操作:

var record_id = $(this).children('.res_id').text();

children only travels a single level down. children只向下走一个台阶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM