Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript .load和.ready之间的关系_Javascript_Jquery - Fatal编程技术网

Javascript .load和.ready之间的关系

Javascript .load和.ready之间的关系,javascript,jquery,Javascript,Jquery,我正在使用jQuery中的.load函数将页面的一部分加载到另一个页面中 $("#loadingDockShotPg").load("include/shot_comments.php?id="+get['id']); 在我加载到id为“loadingDockShotPg”的div中的文件中,我希望jQuery命令能够影响其中的一些元素 正在使用.load <textarea id='newNoteTextarea' class='width100 hidden' placement=

我正在使用jQuery中的
.load
函数将页面的一部分加载到另一个页面中

$("#loadingDockShotPg").load("include/shot_comments.php?id="+get['id']);
在我加载到id为“loadingDockShotPg”的div中的文件中,我希望jQuery命令能够影响其中的一些元素

正在使用
.load

 <textarea id='newNoteTextarea' class='width100 hidden' placement='Write a comment...'></textarea>

问题是我的textarea没有受到jQuery的影响,jQuery应该将placement属性放在textarea的值中。为了完成这项工作,我必须做些什么?

您可能想看看使用
.live()
,(技术上已折旧)或
.on()
在使用
.load()
时附加/绑定到选定元素上的事件

您的
.load()
是一个“活动函数”。加载DOM后,您将向其添加内容。在使用
.load()
添加内容之前,您的
.each()
函数已经执行。要解决此问题,可以在
.load()
作为回调完成时运行
.each()
函数

我应该这样做:

$(function(){
    var inputElements = $("input[placement], textarea[placement]");

    function setInputValue() {
        var self = $(this),
            orAttr = self.attr("placement");

        self
            .val(orAttr)
            .focus(function(){
                if(self.val() == orAttr)
                {
                self.val("");
                }
            })
            .blur(function(){
                if(self.val() == "")
                {
                self.val(orAttr);
                }
            });
    }

    inputElements.each(setInputValue);

    $("#loadingDockShotPg").load("include/shot_comments.php?id="+get['id'], function(){
        inputElements = $("input[placement], textarea[placement]");
        inputElements.each(setInputValue);
    });
});

你能给我举个例子吗?这些链接将包含一些例子,但是你会改变你的代码:$(this.live(“focus”,function()…问题:
$(function(){});
就像
$(document.ready)(function(){});
?@Majed就我所知,是一样的。
$(function(){
    var inputElements = $("input[placement], textarea[placement]");

    function setInputValue() {
        var self = $(this),
            orAttr = self.attr("placement");

        self
            .val(orAttr)
            .focus(function(){
                if(self.val() == orAttr)
                {
                self.val("");
                }
            })
            .blur(function(){
                if(self.val() == "")
                {
                self.val(orAttr);
                }
            });
    }

    inputElements.each(setInputValue);

    $("#loadingDockShotPg").load("include/shot_comments.php?id="+get['id'], function(){
        inputElements = $("input[placement], textarea[placement]");
        inputElements.each(setInputValue);
    });
});