我需要获取以下javascript代码才能使用以下任何链接:
<a href="#" class="example1">http://example.com</a>
<a href="#" class="test">Doesnt work now</a>
Run Code Online (Sandbox Code Playgroud)
单击链接后显示的代码:
<div style='display:none'>
<div id='example1' style='padding:10px; background:#fff;'>
<a href="http://example.com" target="_blank">Link</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要简化的javascript代码来处理我给出的任何class/id值:
<script>
$(document).ready(function(){
$(".example1").colorbox({width:"50%", inline:true, href:"#example1"});
$(".example2").colorbox({width:"50%", inline:true, href:"#example2"});
$(".example3").colorbox({width:"50%", inline:true, href:"#example3"});
$(".example4").colorbox({width:"50%", inline:true, href:"#example4"});
$(".example5").colorbox({width:"50%", inline:true, href:"#example5"});
});
Run Code Online (Sandbox Code Playgroud)
$("[class^='example']").each(function() {
$(this).colorbox({width:"50%",
inline:true,
href:"#example" + $(this).attr("class").replace("example", "")
});
});
Run Code Online (Sandbox Code Playgroud)
甚至更简单:
$("[class^='example']").each(function() {
$(this).colorbox({width:"50%",
inline:true,
href:"#" + $(this).attr("class")
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |