通过父页面中的href从子页面加载特定的id

时间:2013-03-13 20:54:39

标签: jquery jquery-ui-dialog

我正在尝试做的事情 - 如果可能的话 - 是从子页面加载特定的ID并将该内容显示在父页面上的对话框中。我想在点击医疗链接时加载DIV ID“medical”。我希望在href中添加一些加载正确ID的选择器。

使用Javascript:

$(document).ready(function() {
        var $loading = $('<img src="img/loading.gif" alt="loading" class="loading">');
        $('#prod-dialog td a').each(function() {
            var $dialog = $('<div></div>')
                .append($loading.clone());
            var $link = $(this).one('click', function() {
                $dialog
                    .load($link.attr('href'))
                    .dialog({
                        title: $link.attr('title'),
                        width: 300,
                        height: 200,
                        buttons: [
                    {
                        text: "Ok",
                            click: function() {
                        $( this ).dialog( "close" );
                            }
                        },
                    {
                        text: "Cancel",
                            click: function() {
                        $( this ).dialog( "close" );
                            }
                        }
                    ]
                });
                $link.click(function() {
                    $dialog.dialog('open');
                    return false;
                });
                return false;
            });
        });
    });

父母HTML:

<table id="prod-dialog">
            <tr>
              <td><div><img src="img/medical-icon.png" width="26" height="25" />
                <p>Medical</p>
                </div></td>
              <td><a href="medical.htm"><img src="img/dialog-icon_08.png" width="24" height="23" border="0"/></a></td>
              </tr>
</table>

儿童页面HTML:

<div style="display: none;" id="medical" title="Medical">
<table id="prod-content">
      <tr>
        <td><label>Coverage Level</label></td>
        <td>
            <select name="coverlevel" id="coverlevel">
                <option value="0" selected>Employee Only</option>
                <option value="1">Employee + Spouse</option>
                <option value="2">Employee + Children</option>
                <option value="3">Employee + Family</option>
            </select>
        </td>
      </tr>
      <tr>
        <td><label>Premium</label></td>
        <td><input name="premium" type="text" size="30"/></td>
      </tr>
      </table>
    </div>

1 个答案:

答案 0 :(得分:0)

答案如下:

$(document).ready(function() {
    var $loading = $('<img src="img/loading.gif" alt="loading" class="loading">');
    $('#prod-dialog td a').each(function() {
        var $dialog = $('<div></div>')
            .append($loading.clone());
        var $link = $(this).one('click', function() {
            var $cnt = $(this).attr('href') + " #" + $(this).attr('id')
            $dialog
                .load($cnt)
                .dialog({
                    title: $link.attr('title'),
                    width: 300,
                    height: 200,
                    buttons: [
                    {
                        text: "Ok",
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    },
                    {
                    text: "Cancel",
                        click: function() {
                    $( this ).dialog( "close" );
                        }
                    }
                    ]
                });


            $link.click(function() {
                $dialog.dialog('open');
                return false;
            });
            return false;
        });
    });
});