Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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 如何在特定字段后添加类?_Javascript_Jquery - Fatal编程技术网

Javascript 如何在特定字段后添加类?

Javascript 如何在特定字段后添加类?,javascript,jquery,Javascript,Jquery,我有下面的html <input class="form-control dropify" name="photo" type="file"> <button type="button" class="dropify-clear">Remove</button> 使用jquery,您可以使用 下面的代码将选择一个classdropify clear按钮,该按钮位于input with name photo旁边,并将使用jqueryaddClass添加一个类

我有下面的html

<input class="form-control dropify" name="photo" type="file">

<button type="button" class="dropify-clear">Remove</button>
使用jquery,您可以使用

下面的代码将选择一个class
dropify clear
按钮,该按钮位于input with name photo旁边,并将使用jquery
addClass
添加一个类

$(“input[name='photo']”)。下一步(“button.dropify clear”).addClass(“deletephoto”)
.deletephoto{
背景:红色;
颜色:白色;
}


不使用jquery删除
,您可以这样做:

<button type="button" class="dropify-clear deletephoto">Remove</button>
const removeBtn=document.querySelector(“.dropify clear”);
removeBtn.classList.add(“deletephoto”)
.deletephoto{
背景:红色;
颜色:白色;
}


删除
$('.dropify clear').addClass('deletephoto');不清楚何时要应用
deletephoto
类。是在关注输入时还是在什么时候?基本上,您需要使用addClass attritube