如何使用onclick内联调用simplemodal?

我可以在某种程度上使用Eric Martin的simplemodal。 但是我想把它称为内联onclick

像这样内联的东西:

 IBM  

不是这样的:(通常在页面底部)

 $('.free_modal').click(function(e) {var hrefval= $(this).attr("href"); $.modal('', {closeHTML:"", overlayCss: {backgroundColor:"#000", opacity:85}, containerCss:{backgroundColor:"#B9B54F", borderColor:"#B9B54F", border:20, height:555,padding:10, width:1020}, overlayClose:true}); e.preventDefault(); });  

任何人都可以告诉我如何做到这一点。 我阅读了文档,但对我来说并不清楚。 也许这不应该完全与“onclick”内联完成,也许可以调用具有合理默认值的类(即没有高度和宽度的类以及文字URL)。

我在一个simplemodal脚本上有一个以前的相关post来处理图像 ,它给出了:

  $(document).ready(function(){ $(".photo").click(function(e) { var hrefval= $(this).attr("href"); $.modal('', { containerCss: { height:'auto',width:'auto'}, overlayClose: true }); e.preventDefault(); }); });  

我换了$ .modal(’

有什么建议? 我真的想为我所有的模态需求标准化simplemodal。

更新:我使用了Chris Heald的想法,并为iframe simplemodal提出了这个想法。 请注意,它根据内联高度和宽度设置容器大小以及iframe大小。

  $('.ibm_modal').click(function(e) {var hrefval= $(this).attr("href"); var $this = $(this); var height_len = $this.data("height"); var width_len = $this.data("width"); $.modal('', {closeHTML:"", overlayCss: {backgroundColor:"#000", opacity:85}, containerCss:{backgroundColor:"#B9B54F", borderColor:"#B9B54F", border:20, padding:10, height:'height_len+10', width:'width_len+10'}, overlayClose:true}); e.preventDefault(); });  

我只是使用HTML5数据属性和jQuery的data()方法。

 IBM 

然后在页面底部,或$(document).ready()部分:

  

您可以使用“模态”类标记任何元素,并提供数据宽度和数据高度属性,并将正确的Javascript行为附加到正确的元素。 这有一个额外的好处,即从不显眼的Javascript设计目标中获得正确,并且更容易维护。