简体   繁体   中英

why the fancybox is not appearing here?

All I want is this :

$('#divEditable2').fancybox();

I of course tried that, but when it didn't work, I even tried this. Still no output.

Here's my full code :

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="fbTest.aspx.cs" Inherits="InlineEditing.fbTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../jquery-1.4.3.min.js" type="text/javascript"></script>
    <script src="jquery.fancybox-1.3.4.pack.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="~/Scripts/fancybox/fancybox/jquery.fancybox-1.3.4.css"
        media="screen" />
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(function () {

                alert('loading...');
                var divObject = document.createElement('div');
                divObject.setAttribute('id', 'divEditable2');
                var editorContent = '<textarea rows="5" cols="55">sample text' + '</textarea><input type="button" value="Save Edits" id="btnSaveEdits" style="margin-left: 300px;" onclick="HideTextArea(event);"/><input type="button" value="Cancel Edits" id="btnCancelEdits" style="margin-left: 5px;" onclick="DoCleanUp();"/>';

                $('#divEditable2').fancybox({
                    'modal' : true,
                    'type' : 'inline',
                    'autoDimensions': false,
                    'width': '700',
                    'height': '320',
                    'showCloseButton': false,
                    'hideOnOverlayClick': false,
                    'enableEscapeButton': false,
                    'content': editorContent
                });
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="display: none;">
        <div id="divEditable2">
            This is the test div.</div>
    </div>
    <input type="button" id="btn" value="show" />
    </form>
</body>
</html>

On click of the button, there is no error(firebug), but still I don't understand why the fancybox does not appear??? All I want is, to show a div inside a fancybox. There must be something really-really stupid I'm missing out on, but just could not figure it out myself. Thanks.

Try doing some thing like .

Keep the div in the markup don't generate it dynamically.

Append the text area thing to div and then give a call to your fancy box.

It seems to me that you are misunderstanding the logic of fancybox. What this line does

$('#divEditable2').fancybox();

... is to bind fancybox to the selector with id="divEditable2" . You would actually need to click on that selector in order to fire fancybox ...of course you can't, first because is hidden and second because is not a link, is a DIV

What you can try is to append the value of the variable editorContent to the selector '#divEditable2' and then target the second as href , something like:

$('#divEditable2').append('<textarea rows="5" cols="55">sample text' + '</textarea><input type="button" value="Save Edits" id="btnSaveEdits" style="margin-left: 300px;" onclick="HideTextArea(event);"/><input type="button" value="Cancel Edits" id="btnCancelEdits" style="margin-left: 5px;" onclick="DoCleanUp();"/>');

then replace this line of your code:

$('#divEditable2').fancybox({

by this:

$.fancybox({

and replace this line:

'content': editorContent

by this:

'href': '#divEditable2'

Additionally, in order to clean up your code, don't use integer values with quotes so these

'width': '700',
'height': '320',

should be

'width': 700,
'height': 320,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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