// Rate videos start
$('[value="bad"]').click(function (e) {
console.log($(this));
alert($(this).data("primary"));
});
echo '<div class="carousel-inner">';
echo '<div class="item active">';
echo '<h4>' . $vid->VIDEO_NAME . '</h4>';
echo '<input type="text" class="" data-primary="' . $vid->ID . '" value="' . $vid->ID . '">';
echo '<video width="500" height="281" controls>';
echo '<source src="' . base_url() . $vid->VIDEO_URL . '" type="video/mp4">';
echo 'Your browser does not support the video tag.';
echo '</video>';
echo '</div>';
echo '</div>';
echo '</div>';
我正在尝试获取每个视频元素的ID,但它返回undefined。
答案 0 :(得分:0)
在文本字段中设置id
或class
等标识符,然后为该对象上的click事件添加一个侦听器:
// If you set by Class
$('.textToClick').click(function (e)
{
alert($(this).data("primary"));
});
// If you set by ID
$('#textToClick').click(function (e)
{
alert($(this).data("primary"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Setting identifier by Class -->
<input type="text" class="textToClick" data-primary="dataPrimaryFromClass" value="Class identifier">
<!-- or setting identifier by id -->
<input type="text" id="textToClick" data-primary="dataPrimaryFromID" value="ID identifier">