从加载到 FancyBox 的页面内按钮调用的 JS 函数将 onclick 属性添加到父页面中的 ImageButton

发布于 2024-10-02 06:25:02 字数 1940 浏览 3 评论 0 原文

我在 ASP.NET 用户控件(内容页内)中使用 "FancyBox"。 我希望在加载到 FancyBox 的页面上的按钮上单击(客户端单击),将调用 JavaScript 函数,并且在该函数中我想启用父页面中包含的 ImageButton(打开该页面的页面) FancyBox模态对话框)并动态添加“onclick” 其财产。

在包含 ImageButton 的表单的代码文件中,我添加了一个属性,以便可以使用 JQuery

ibtnDeleteImage.Attributes.Add("serverID", "ibtnDeleteImage");

轻松选择它。这是用于将 onclick 属性添加到 ImageButton 的函数

 function addOnclick() {

   //Get ref to the delete article thumbnail image button
   var $ibtnDeleteThumbImage = $("input[serverId='ibtnDeleteImage']", window.parent.document);

   //Enable the image button
   $ibtnDeleteThumbImage.removeAttr("disabled");

   //Add  onclick property to the ImageButton assign it an  event handler and avoid post back to the server
   $ibtnDeleteThumbImage[0].onclick = function() { deleteThumbnailImage(); return false; };

    }

这是事件处理程序:

function deleteThumbnailImage() {
   var dialogMessage = "Are you sure you want \n to delete the article thumbnail";
   if (confirm(dialogMessage)) {
       var $ibtnDeleteThumbImage = $("input[serverId='ibtnDeleteImage']", window.parent.document);
       //Remove the onclick property from the ImageButton
       $ibtnDeleteThumbImage.removeAttr("click");
       //Disable the ImageButton
       $ibtnDeleteThumbImage.attr('disabled', 'disabled');

   }

}

我正在使用语法

 $ibtnDeleteThumbImage[0].onclick = function() { deleteThumbnailImage(); return false; };

而不是

$ibtnDeleteThumbImage.attr("onclick", "deleteThumbnailImage();return false;");

因为所描述的问题 此处

我的问题: 此语法在由包含在常规 Iframe 中加载的页面的按钮调用的 JavaScript 函数中运行良好,但在加载到 FancyBox 的页面中包含的页面中则不起作用。 ( onclick 属性没有添加到 ImageButton 并且有一个回发到服务器)

有谁知道问题是什么以及解决方案是什么?

谢谢

I am using "FancyBox" in ASP.NET User Control (inside a Content Page).
I want that a click(client side click) on a button 'placed on the page loaded into the FancyBox ,will call a JavaScript function, and in that function I want to enable a ImageButton contained in the parent page(The page that opened the FancyBox modal dialog)and Dynamically add 'onclick'
property to it.

In the code file of the form that contains the ImageButton I added an attribute so I can easily select it using JQuery

ibtnDeleteImage.Attributes.Add("serverID", "ibtnDeleteImage");

Here is the function used to add the onclick property to the ImageButton

 function addOnclick() {

   //Get ref to the delete article thumbnail image button
   var $ibtnDeleteThumbImage = $("input[serverId='ibtnDeleteImage']", window.parent.document);

   //Enable the image button
   $ibtnDeleteThumbImage.removeAttr("disabled");

   //Add  onclick property to the ImageButton assign it an  event handler and avoid post back to the server
   $ibtnDeleteThumbImage[0].onclick = function() { deleteThumbnailImage(); return false; };

    }

Here is the event handler :

function deleteThumbnailImage() {
   var dialogMessage = "Are you sure you want \n to delete the article thumbnail";
   if (confirm(dialogMessage)) {
       var $ibtnDeleteThumbImage = $("input[serverId='ibtnDeleteImage']", window.parent.document);
       //Remove the onclick property from the ImageButton
       $ibtnDeleteThumbImage.removeAttr("click");
       //Disable the ImageButton
       $ibtnDeleteThumbImage.attr('disabled', 'disabled');

   }

}

I am using the syntax

 $ibtnDeleteThumbImage[0].onclick = function() { deleteThumbnailImage(); return false; };

And not

$ibtnDeleteThumbImage.attr("onclick", "deleteThumbnailImage();return false;");

Because of the problem described here

My problem :
This syntax work well in a javascript function called by a button contained page loaded in a regular Iframe but not in one contained in page loaded into FancyBox.
(The onclick property is not added to the ImageButton and there is a postback to the server)

Does anyone know what is the problem and what is the solution to it ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷路的信 2024-10-09 06:25:02

这可能是跨脚本问题。

在你的 addOnClick 函数中,你可以做这样的事情

$("input[serverId='ibtnDeleteImage']").click(function() { 
    // perform delete logic here
}).removeAttr("disabled");

That could be a cross scripting issue.

In your addOnClick function, you could do something like this

$("input[serverId='ibtnDeleteImage']").click(function() { 
    // perform delete logic here
}).removeAttr("disabled");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文