2017-12-16 1 views
0

// 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>';

私は、各video要素のIDを取得しようとしているが、それはundefinedを返します。何か案は?

+1

'値= bad'を持つ要素がありません提供されたコードサンプル。 –

+0

レンダリングされたhtmlのスニペットを与えてください。 – DecoderReloaded

+0

私の答えはあなたのために働いたのですか? – Ivan86

答えて

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">

関連する問題