gpt4 book ai didi

javascript - 创建多个函数

转载 作者:行者123 更新时间:2023-11-28 21:13:24 25 4
gpt4 key购买 nike

我将尽力尽可能清楚地阐明这个问题。

这就是我正在尝试做的事情:

元素:- 按钮- 模态框- 功能

申请要求:

  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

但我知道这是因为我试图根据页面上有多少个 div 来调用同一个函数(例如 10 次)。

按钮 Jquery 接线:

$('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 : {}
});
};

关于javascript - 创建多个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8183346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com