创建多个功能

Creating Multiple Functions

本文关键字:功能 创建      更新时间:2023-09-26

我尽量把这个问题讲清楚。

我要做的是:

元素:——按钮-模态盒——功能

应用程序要求:

  1. 我需要在一个页面上有一个按钮,当点击它调用一个函数称为newcontent。该函数需要有自己的函数唯一的ID,因为我有一个特定的pageID显示在模态框
  2. 在模态框函数中,我用一个特定的ID,但我也使用.each函数来获取特定的DIV ID

下面是当前的模态框代码:

function newcontent() {    
    $('div.heriyah').each(function() {        
        $.fallr('show', {
            content     :  '<iframe width=620" height="600" src="<? echo $URL ?>/manage_content.php?id=<? echo $pageID; ?>&div='+ this.id +'"></iframe>',
            width       : 620 + 5, // 100 = for width padding
            height         : 600,
            closeKey        : true,
            closeOverlay    : true,
            buttons     : {}
        }); 
    });
}

我将得到如下错误:

uncaught  exception: Can't create new message with content: "<iframe 
width=620" height="600" 
src="http://www.brandonrray.com/Heriyah/admin/manage_content.php?id=1&div=sermons_home"></iframe>",
past message with content "<iframe width=620" height="600" 
src="http://www.brandonrray.com/Heriyah/admin/manage_content.php?id=1&div=up_events_home"></iframe>"
is still active

但我知道这是因为我试图调用相同的函数,如10次,这取决于页面上有多少div。

Button Jquery Wiring:

$('div.heriyah').each(function() { 
$('div.heriyah').append('<div id="add_button_container"><a onClick=newcontent_'+ this.id +'();return false><div id="add_button" class="edit_links">+ ADD NEW CONTENT</div></a></div></div><div class="clear"></div><div class="placeable"></div>');
}); 

谁能把我在正确的方向为这个应用程序,如果你需要我更清楚,请让我知道。我不想再被踢出这些论坛!

不是每次单击按钮时应用each,而是使用回调函数并使用存储在按钮元素中的参数触发newContent。参数也可以是按钮的任何属性。

$('button[class=yours]').click(function () {newContent(this.id)});
// If you want to pass the DIV ID from the button
// $('button[class=yours]').click(function () {newContent($(this).attr('div-id')});
//
var newContent = function (uniqueId) {
    $.fallr('show', {
              content     :  '<iframe width=620" height="600" src="<? echo $URL ?>/manage_content.php?id=<? echo $pageID; ?>&div='+ uniqueId +'"></iframe>',
              width       : 620 + 5, // 100 = for width padding
              height         : 600,
              closeKey        : true,
              closeOverlay    : true,
              buttons     : {}
          }); 
};