我有这个功能:
$(function() {
$('#toggle-event').change(function() {
if($(this).prop('checked') == true){
$('.textfield, .editable_textfield').toggleClass('textfield editable_textfield');
$('.textfield, .editable_textfield').editable('option', 'disabled', false);
$('.editable_selectfield_1').editable({
source: [
{value: 'ja', text: 'Ja'},
{value: 'nee', text: 'Nee'},
],
});
$('.editable_selectfield_1').editable('option', 'disabled', false);
}
else
{
$('.textfield, .editable_textfield').editable('option', 'disabled', true);
$('.editable_selectfield_1').editable('option', 'disabled', true);
}
});
})
该函数可以通过以下方式触发:
<input id="toggle-event" type="checkbox" data-toggle="toggle" data-size="mini" data-on="<span class='glyphicon glyphicon-pencil'></span>" data-off="<span class='glyphicon glyphicon-pencil'></span>" data-onstyle="danger">
但现在我希望此按钮在同一页面上的多个位置显示。 ID需要是uniqye才能运行脚本,如何实现这一点?
最佳答案
使用类名而不是 ID 作为选择器。在切换项上使用相同的类名。
<input class="toggle" id="toggle-event" type="checkbox".... >
$('.toggle').change(function() { ....
关于javascript - 如何从多个起点触发一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59106228/