如何从 $(this).context 获取输入值

How to get the input value from $(this).context

本文关键字:context 获取 输入 this      更新时间:2023-09-26

我的完整日历外部事件显示如下

<?php foreach ($plants as $plant) { ?>
      <div class='fc-event evt'>
           <input type="hidden" value="<?php echo $plant->hcpd_id;?>" class="abc">
           <p class="evt_name"><?php echo $plant->hcpd_name;?></p>
      </div>
<?php } ?>

这是我的j查询

$('#external-events2 .fc-event').each(function() {
  var str = $(this).context;
  $(this).data('event', {
    title: $.trim($(this).text()),
    stick: true, 
    color : '#4AC948',
    className : "sub",
    id : //need to add the id here
  });

});

我想为每个事件提供一个特定的 ID。(取自数据库。它在隐藏输入字段中给出)

以下是生成的div 之一。我想获取以下 $(this).context 结果的隐藏 id

<div class="fc-event evt ui-draggable ui-draggable-handle">
    <input type="hidden" value="1" class="abc">
    <p class="evt_name">My Plant 1</p>
</div>

关于如何检索它的任何想法。我尝试了字符串替换,但没有奏效。

您使用什么事件?例如,如果您使用的是点击事件:

$('.fc-event').click(function(){
    //Get the ID
    var eventID = $(this).find('input[type="hidden"]').val();
    //Do whatever you want with the ID here.
});