Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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
Jquery-如何将文本添加到上面div中的文本框中?_Jquery - Fatal编程技术网

Jquery-如何将文本添加到上面div中的文本框中?

Jquery-如何将文本添加到上面div中的文本框中?,jquery,Jquery,当用户单击“删除”时,我正在尝试将文本添加到下面div中的隐藏文本框中 Html 我在页面上有几个这样的“行”,因此我无法按id引用文本框。问题是这行: $(this).parent().find(".documentDelete input").val("True"); $(this).parent()是按钮()的直接父项,您的隐藏字段不在其中,因此它不会找到它 为了避免重复调用parent(),我建议如下: $(".delDocButton").click(function() {

当用户单击“删除”时,我正在尝试将文本添加到下面div中的隐藏文本框中

Html


我在页面上有几个这样的“行”,因此我无法按id引用文本框。

问题是这行:

$(this).parent().find(".documentDelete input").val("True");  
$(this).parent()
是按钮(
)的直接父项,您的隐藏字段不在其中,因此它不会
找到它

为了避免重复调用
parent()
,我建议如下:

$(".delDocButton").click(function() {
    var $container = $(this).parent().parent();
    $container.toggle();  
    $(".documentDelete input",$container).val("True");  
    return false;
});

现场示例:

问题在于这一行:

$(this).parent().find(".documentDelete input").val("True");  
$(this).parent()
是按钮(
)的直接父项,您的隐藏字段不在其中,因此它不会
找到它

为了避免重复调用
parent()
,我建议如下:

$(".delDocButton").click(function() {
    var $container = $(this).parent().parent();
    $container.toggle();  
    $(".documentDelete input",$container).val("True");  
    return false;
});
现场示例:

更换您的线路

$(this.parent().find(“.documentDelete input”).val(“True”)

用这个

$(this).parent()同级(.documentDelete”).find(“input”).val(“True”)

更换您的线路

$(this.parent().find(“.documentDelete input”).val(“True”)

用这个

$(this).parent()同级(.documentDelete”).find(“input”).val(“True”)

即使这样也可以:

 $(this).parent().find(".documentDelete").find('input').val("True");
即使这样也应该有效:

 $(this).parent().find(".documentDelete").find('input').val("True");

你也会检查这个


希望它有用的

u也会检查这一点


希望它能有效地切换行,但仍然不会将隐藏字段值设置为true@Beginner-我错过了一个下线的
$
。。。重新检查切换行的代码。但仍不会将隐藏字段值设置为true@Beginner-我错过了一个下线的
$
。。。重新检查代码。