Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

javascript - 如何从多个起点触发功能?(How to trigger an function from multiple starting points?)

I have this function:(我有这个功能:)

$(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); } }); }) This function can be triggerd by:(此功能可以通过以下方式触发:) <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"> But now I want this button to be shown an multiple places on the same page.(但是现在我希望此按钮在同一页面上显示多个位置。) The ID needs to be uniqye to be able run the script, how to achieve this?(ID需要是唯一的才能运行脚本,如何实现呢?)   ask by Muiter translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use a class name as your selector instead of an ID.(使用类名作为选择器而不是ID。)

Use the same class name on the toggle items.(在切换项上使用相同的类名。) <input class="toggle" id="toggle-event" type="checkbox".... > $('.toggle').change(function() { ....

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...