0

我有几个表是在 reader.php 的 foreach 中生成的

<table class="object_list_<?php echo $title; ?>">

在同一个文件中有一个 jquery 调用的链接:

<a href="#" onclick="show_object('<?php echo $itemId.','.$title; ?>')"><?php echo (string)$flat.'</a><br />'; ?>

我在处理程序文件 catalogue.php 中的 jQuery 函数如下所示:

<script>
    function show_object(itemid,object_type){
        var request = $.ajax({
            url: "show_object.php",
            type: "GET",
            data: "id="+ itemid,
            dataType: "html"
        });
        $(table['.object_list_' + object_type]).hide();
        request.done(function(msg) {
            $(".show_object").append(msg);          
        });
        request.fail(function(jqXHR, textStatus) {
            alert( "Request failed: " + textStatus );
        });
    }       
</script>

问题在于 hide() 函数

$(table['.object_list_' + object_type]).hide();

这不起作用。请注意,这与其他文件中object_type的相同$title,我通过 a href javascript 调用传递它。

我一直在stackoverflow和google上搜索,但我找不到错误。它正确加载 show_object.php,但不隐藏表格。

我也尝试了其他几个版本,例如:

$('.object_list_' + object_type).hide();

并首先在变量中添加数据,然后在隐藏函数中添加数据.. 无济于事

4

3 回答 3

0
$(table['.object_list_' + object_type]).hide();

是不正确的,你必须使用你的第二个陈述:

$('.object_list_' + object_type).hide();

甚至更好

$('table.object_list_' + object_type).hide();

尝试在“隐藏”调用之前提醒“object_type”,并尝试通过 firebug/chrome 控制台手动执行它,我认为你有一个错误。

发生了什么 ?

于 2013-04-16T08:22:50.800 回答
0

您是否尝试过使用表格上的类而不是内联 onclick 来连接它?

您可以使用 jQuery 从表中提取您需要的任何信息。这是一个粗略的大纲,希望这有帮助吗?在这种情况下,我会将您想要的东西的 id 放在 a 的 data-id="" 属性中,这样可以省去麻烦。

$('table.class a').click(function(e){

    /* Stop normal a click action by preventing default */
    e.preventDefault();

    /* Get the item id and define a $this to use later */
    var itemId = $(this).attr('data-id'), $this = $(this);

    /* Use nicer $.get syntax, pass the id */
    $.get('show_object.php',{
        id:itemId
    },function(data){

        /* Put your data in the target */
        $('target').append(data);

        /* Use the $this item to hide the a you clicked on */
        $this.hide();
    }
});

希望有帮助,如有必要,我可以尝试更具体的东西吗?

于 2013-04-16T08:40:54.157 回答
0

感谢所有试图提供帮助的人!我犯了一个愚蠢的错误。

我必须用 ' 标记转移通过 javascript 传递的变量。

<a href="#" onclick="show_object('<?php echo $itemId."','".$title; ?>')"><?php echo (string)$flat.'</a><br />'; ?>

输出必须是这样的:

<a href="#" onclick="show_object('2013084','Kerrostalot')">4h,k,sauna,terassi</a>

javascript调用假定它们是一个变量,而不是两个..

我觉得好傻。。。

于 2013-04-16T09:36:34.597 回答