Javascript 如何使用jquery为每个按钮设置功能? 不要使用内联代码。话虽如此,您可以将员工姓名添加为data name=“…”,然后使用onclick=“setrementer(this);”。现在改用function setrementer(btn),在内部使用
如何使用jquery为每个按钮设置功能?Javascript 如何使用jquery为每个按钮设置功能? 不要使用内联代码。话虽如此,您可以将员工姓名添加为data name=“…”,然后使用onclick=“setrementer(this);”。现在改用function setrementer(btn),在内部使用,javascript,jquery,cordova,Javascript,Jquery,Cordova,如何使用jquery为每个按钮设置功能? 不要使用内联代码。话虽如此,您可以将员工姓名添加为data name=“…”,然后使用onclick=“setrementer(this);”。现在改用function setrementer(btn),在内部使用btn.dataset.name从按钮中获取员工姓名。@Chris G在按钮中添加data name=“…”是什么意思?编写HTML字符串并不容易,但类似”的东西应该可以工作,谢谢@Chris G它的工作方式完全相同;将其添加为按钮的data
不要使用内联代码。话虽如此,您可以将员工姓名添加为
data name=“…”
,然后使用onclick=“setrementer(this);”
。现在改用function setrementer(btn)
,在内部使用btn.dataset.name
从按钮中获取员工姓名。@Chris G在按钮中添加data name=“…”是什么意思?编写HTML字符串并不容易,但类似”
的东西应该可以工作,谢谢@Chris G它的工作方式完全相同;将其添加为按钮的data diff
属性,然后在函数中使用btn.dataset.diff
。
localStorage['serviceURL'] = "https://cors-anywhere.herokuapp.com/http://goodsbuy.000webhostapp.com/";
var serviceURL = localStorage['serviceURL'];
var scroll = new iScroll('wrapper', { vScrollbar: false, hScrollbar:false, hScroll: false });
var employees;
$(window).load(function() {
setTimeout(getEmployeeList, 100);
});
$(document).ajaxError(function(event, request, settings) {
});
function getEmployeeList() {
$('#busy').show();
$.getJSON(serviceURL + 'getemployees.php', function(data) {
$('#busy').hide();
$('#employeeList li').remove();
employees = data.items;
$.each(employees, function(index, employee) {
var valuestop = employee.title;
var now = "30/11/2019 " + valuestop;
var then = new moment();
var difference = moment.utc(moment(now,"DD/MM/YYYY HH:mm:ss").diff(moment(then,"DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss");
$('#employeeList').append('<li>'+
'<img src="js/citybus.png" class="list-icon"/>' +
'<p class="line1">' + employee.firstName + '</p>' +
'<p class="line2">' + difference +'</p>' +
'<button class="bubble" onclick="setReminder();">' + '<center><img src="js/bell.png" style="height:15px;width:15px;"/></center>' + '</button></li>');
});
setTimeout(function(){
scroll.refresh();
});
});
}
function setReminder() {
cordova.plugins.notification.local.schedule({
id: 1,
title: employee.firstName,
text: "Your Bus Will Soon Be Here",
sound: "js/when.mp3",
icon: "js/citybus.png"
});
}