我对此非常陌生,我希望获得每行HTML的数据评级值,并为每行输出相同的图像多次,具体取决于每个值,使用jQuery / Javascript。
以下是HTML的示例:
<div class="review-value" data-rating="5"></div>
<div class="review-value" data-rating="7"></div>
我怎样才能做到最好?
答案 0 :(得分:0)
您可以使用此代码:
$('.review-value').each(function (index, value) {
alert('div' + index + ':' + $(this).attr("data-rating"));
});
答案 1 :(得分:0)
final Handler handler = new Handler();
final Runnable Update = new Runnable() {
public void run() {
if (currentPage == NUM_PAGES-1) {
currentPage = 0;
timer.cancel();
timer = new Timer();
}
mPager.setCurrentItem(currentPage++, true);
}
};
timer = new Timer(); // This will create a new Thread
timer .schedule(new TimerTask() { // task to be scheduled
@Override
public void run() {
handler.post(Update);
}
}, 500, 3000);
是HTML的属性。您也可以将其与Jquery mPager
循环一起使用,并将值存储在Data
each
Array
答案 2 :(得分:0)
其中一种方法。
$('.review-value').each(function() {
for (var i = 0, len = parseInt($(this).attr("data-rating")); i < len; i++) {
$('<img src="#" />').appendTo($(this))
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="review-value" data-rating="5"></div>
<div class="review-value" data-rating="7"></div>
答案 3 :(得分:0)
JQuery有data()
可以帮助您获取任何数据属性的值:
try {
// Class.forName("org.apache.derby.jdbc.ClientDriver");
con = DriverManager.getConnection("jdbc:derby://localhost:1527/pavillons","saiid","saiid");
Query =" SELECT NOM_PRENOM FROM SAIID.ETUDIANT_PAV WHERE PAVILLONS = ? AND CHAMBRE = ? " ;
ps = con.prepareStatement(query);
ps.setString(1, pav);
ps.setString(2, ch);
reslt = ps.executeQuery();
afuf= reslt.getString("NOM_PRENOM");
System.out.println ("dooooooooo"+afuf);
JOptionPane.showMessageDialog(null, "Query Executed");
return reslt;
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
return reslt;
}
&#13;
$(document).ready(function() {
$(".review-value").each(function() {
console.log('Rating: ' + $(this).data('rating'));
});
});
&#13;