如何使用jquery删除textarea中的值

luc*_*cky 1 html jquery

嗨我在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)

有人请告诉我如何清除这两个字段,以便在页面重新加载后这些值不应该存在.

the*_*dox 6

更改您的选择器如下:

$(this).parents('.tblinput.sname.pvar').val('');
$(this).parents('.tblinput.semails.txtInputta.pvar').val('');
Run Code Online (Sandbox Code Playgroud)

对于class元素的多个元素,您需要在没有任何空格的情况下class使用这些名称来连接dot(.)它们,如上所述.


你的选择者做了什么

您的选择器.tblinput sname pvardescendant selector格式.这意味着它的搜索 pvar范围内snameANS snametblinput和同为第二个.


相关参考:


根据评论

$(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)