6

我使用 jQUery UI Position 插件: http: //jqueryui.com/position/将我的图标定位在网页上。选择器从数据库中获取并使用 PHP 在 $myselector 变量中输出到 JS。这是我当前的代码:

var element_selector='<?php echo $myselector;?>';

$('#inline_docxdiv .Featured.Slider').position({
my: "center",
at: "right top",
of: $(element_selector)

});

//append icons,applicable to all

$(divname<?php echo $uniqueid;?>).append('<div id="inline_docxdiv" class="<?php echo $uniqueid;?>"><div id="helpericons_display"><a class="<?php echo $title_toolsetdisplayed;?>" id="questionmarkicon_inlinedoc" title="Display Explanation"><img src="<?php echo $helper_iconpng;?>"></a><a target="_blank" href="<?php echo admin_url().'post.php?post='.$id_toolsetdisplayed.'&action=edit';?>" class="<?php echo $title_toolsetdisplayed;?>" id="sourceicon_inlinedoc" title="View source"><img src="<?php echo $helpersource_iconpng;?>"></a></div></div>');

但是,图标未正确附加,并在控制台中返回错误:

未捕获的类型错误:无法读取未定义的属性“nodeType”

奇怪的是,如果我在 JS 代码中硬编码选择器(不是由 PHP 输出),一切正常,并且控制台中没有返回错误。这是我硬编码元素选择器的代码:

var element_selector='.idoc-featured-slider';

有没有办法使用 PHP 输出选择器而不遇到错误?谢谢你的帮助。

4

5 回答 5

15

I ran into a similar issue. I was getting the following error:

Uncaught TypeError: Cannot read property 'nodeType' of undefined

With these dialog position configuration values:

position: {my: "center", at: "left top", of: "window"}

Per the jQuery UI documentation, the value of the "of" property is an object rather than a string. So, when I changed the position values to the following:

position: {my: "center", at: "left top", of: window}

the error disappeared.

于 2013-07-07T22:15:01.520 回答
3

问题是由于of:$()对象/选择器无效时无法正常工作。

于 2014-07-22T13:48:07.320 回答
0

如果任何标签未关闭,请检查您的代码。我尝试了同样的方法,它工作正常。显然,我有一个额外的标签

于 2014-06-16T21:00:46.697 回答
0

通常,当您不应用 prop() 之类的方法的属性时,会发生这种错误。例如:$(#"id").prop()如果您没有指定其属性,也会发生此错误。

于 2016-10-28T09:31:25.127 回答
0

在我的情况下,我只是在我的错误 [DataTables 警告:表 id=bootstrap-data-table2 - Requested unknown parameter '0' for row 0' 中更改了以下内容。有关此错误的更多信息,请参阅http://datatables .net/tn/4] 不见了:

从:

                                    [enter image description here][1] <tbody>
                                            @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
                                            {

                                                <tr>
                                                    @if (item.Approved == "1")
                                                    {
                                                        <td>@item.Date</td>
                                                        <td>@item.Date</td>
                                                        <td>@item.Type</td>
                                                        <td>@item.Amount</td>
                                                                               }
                                                </tr>

                                            }
                                        </tbody>


                        TO:


                                         <tbody>
                                            @foreach (var item in Model.HRMS_Tbl_ExpenseClaimModelList)
                                            {
                                              if (item.Approved == "1")
                                                    {
                                                <tr>

                                                        <td>@item.Date</td>
                                                        <td>@item.Date</td>
                                                        <td>@item.Type</td>
                                                        <td>@item.Amount</td>

                                                </tr>
                                                    }
                                            }
                                        </tbody>                            
于 2019-01-30T08:22:00.160 回答