Javascript 使用.last()隐藏最后一个元素

Javascript 使用.last()隐藏最后一个元素,javascript,jquery,Javascript,Jquery,我有以下表格: <form id="P" enctype="multipart/form-data" action="/" method="post"> <input class="userImage" onchange="readURL(this);" type="file" name="profileImage" accept="image/x-png, image/gif, image/jpeg, image/bmp"> </form> 我

我有以下表格:

<form id="P" enctype="multipart/form-data" action="/" method="post">
    <input class="userImage" onchange="readURL(this);" type="file" name="profileImage" accept="image/x-png, image/gif, image/jpeg, image/bmp">
</form>


我有一个JavaScript回调函数,我试图隐藏最后的<代码> < p>如果您想查找最后出现的元素,请考虑使用选择器:

// Hide your last image (within your P <form>)
$('#P .userImage:last').hide();
// Append a new one here 
$('#P').append('<input class="userImage" onchange="readURL(this);" ...');
//隐藏上一张图像(在P中)
$('#P.userImage:last').hide();
//在这里附加一个新的

追加(‘p’p’)。(< p>如果您想查找最后出现的元素,请考虑使用选择器:

// Hide your last image (within your P <form>)
$('#P .userImage:last').hide();
// Append a new one here 
$('#P').append('<input class="userImage" onchange="readURL(this);" ...');
//隐藏上一张图像(在P中)
$('#P.userImage:last').hide();
//在这里附加一个新的
$('#P')。追加('

尝试将隐藏()选择器更改为:

$(“#P>.userImage:last child”).hide();

尝试将您的hide()选择器更改为:


$(“#P>.userImage:last child”).hide()

您的逻辑是正确的。只是一个简单的使用错误

使用以下命令:

$("#P .userImage").last().hide();

你的逻辑是正确的。只是一个简单的使用错误

使用以下命令:

$("#P .userImage").last().hide();

谢谢Rion,我投了赞成票,结果很好。我之所以选择我的答案,是因为它利用了我最初的最后一个()答案。看起来有一些人为了好玩而投反对票……谢谢Rion,我投了赞成票,结果很好。我之所以选择我的答案,是因为它利用了最后一个()答案我一开始是这样的。看起来这上面有些人为了好玩而投了反对票。。。