嗨我在div表中有一行如下:
<div class="tbody plb" id="impemail">
<div class="tbc1" style="border-right:none;">
<input class="tblinput sname pvar" type="text">
<input type="hidden" class="ppre" value="">
</div>
<div class="thc2" style=" width: 75%; border-left:1px dotted #CFCFCF;">
<textarea class="tblinput semails txtInputta pvar" style="font-size:13px;"></textarea>
<input type="hidden" class="ppre" value="">
<div class="errmsg emailerr"></div>
</div>
<div class="hideRow" style="width:20px;float:right;padding:15px 0px 0px 0px;">
<img src="../../../images/redcross.png" alt="" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我点击使用jQuery函数的类"hideRow"时,我尝试编写函数来删除这一行,如下所示,这里我想清除hideRow函数正在进行的输入和textarea字段,以便在刷新页面后值不应该在行中.我试过的jQuery函数如下:
$(function () {
// Delete row from PTC grid
$('.hideRow').live("click", function () {
$(this).parents('.plb').hide("slow", function () {
$(this).parents('.tblinput sname pvar').val('');
$(this).parents('.tblinput semails txtInputta pvar').val('');
});
})
});
Run Code Online (Sandbox Code Playgroud)
有人请告诉我如何清除这两个字段,以便在页面重新加载后这些值不应该存在.
更改您的选择器如下:
$(this).parents('.tblinput.sname.pvar').val('');
$(this).parents('.tblinput.semails.txtInputta.pvar').val('');
Run Code Online (Sandbox Code Playgroud)
对于class元素的多个元素,您需要在没有任何空格的情况下class使用这些名称来连接dot(.)它们,如上所述.
您的选择器.tblinput sname pvar是descendant selector格式.这意味着它的搜索 pvar范围内snameANS sname内tblinput和同为第二个.
相关参考:
$(function () {
// Delete row from PTC grid
$('.hideRow').live("click", function () {
$(this).closest('.plb').hide("slow", function () {
$(this).find('.tblinput.sname.pvar, .tblinput.semails.txtInputta.pvar').val('');
});
})
});
Run Code Online (Sandbox Code Playgroud)