简体   繁体   English

jQuery / JavaScript内容替换?如何可重用

[英]jquery/javascript content replace?how reusable

http://img163.imageshack.us/img163/6248/93306989.jpg http://img163.imageshack.us/img163/6248/93306989.jpg

the images above show what i want, 上面的图片显示了我想要的,

i'm using Facebox to do the pop up content,so how can i make the pop up content dynamic? 我正在使用Facebox制作弹出内容,那么如何使弹出内容动态化?

<script type="text/javascript">
    $(function() {
        $('.openExample').click(function() {
            $.facebox($('#exampleSource').val()); 
            return false;
        });
    });
</script>

the code above work just fine,but how can edit to reusable??? 上面的代码工作正常,但是如何编辑才能重用?

<form>
<textarea id="exampleSource" class="expand">
<html>
<body>

<h1>Heading</h1>

<p>paragraph.</p>

</body>
</html> 
</textarea>
<input type="Submit" value="Submit" class="openExample" />
<input type="reset" value="Reset" />
</form>

Create a function that accepts string or id of the element. 创建一个接受元素的字符串或id的函数。

example: 例:

function popWindow(elementID)
{

    $('.openExample').click(function() {
        $.facebox($(elementID).val()); 
        return false;
    });
}

call it like this popWindow('#exampleSource'); 这样称呼它popWindow('#exampleSource');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM