[英]how to remove the value in the textarea using jquery
hi i have a row in my div table as follows: 嗨,我在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>
and i tried in writing the function to remove this row when i click the class "hideRow" using jQuery function as follows, here i want to clear the input and textarea fields while the hideRow function is going on, so that after refreshing the page the values should not be there in the row. 并且我尝试编写函数以使用jQuery函数单击类“ hideRow”时删除此行,如下所示,这里我想在hideRow函数进行时清除输入和textarea字段,以便刷新页面后值不应在该行中存在。 the jQuery function i tried is as follows:
我尝试的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('');
});
})
});
anyone please tell me how to clear these two fields, so that after the page reloads these values should not be there. 任何人都请告诉我如何清除这两个字段,以便在页面重新加载后不存在这些值。
Change your selector like following: 如下更改您的选择器:
$(this).parents('.tblinput.sname.pvar').val('');
$(this).parents('.tblinput.semails.txtInputta.pvar').val('');
For multiple class
es of an element, you need join those class
names using dot(.)
without any space to make a selector among them like above. 对于一个元素的多个
class
,您需要使用dot(.)
将这些class
名连接起来,而没有任何空间像上面那样在它们之间进行选择。
Your selector .tblinput sname pvar
is descendant selector
format. 选择器
.tblinput sname pvar
是descendant selector
格式。 That means its searching pvar
within sname
ans sname
within tblinput
and same for the second one. 这意味着它在
tblinput
sname
和sname
搜索pvar
,第二个相同。
Related refs: 相关参考:
$(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('');
});
})
});
Your main problem is that, within the callback for .hide()
, the value of this
refers to the element being hidden; 您的主要问题是,在
.hide()
的回调中, this
的值表示隐藏的元素。 correct traversal technique is .find()
as in $(this).find('.tblinput.sname.pvar').val('');
正确遍历技术
.find()
如$(this).find('.tblinput.sname.pvar').val('');
. 。
Javascript Java脚本
$(function () {
// Delete row from PTC grid
// .live() is deprecated, port to .on()
$('.hideRow').live("click", function () {
//use .closest() instead of .parents() - less traversing
$(this).closest('.plb').hide("slow", function () {
// search down, not up - and no space between class selectors
$(this).find('.tblinput.sname.pvar').val('');
$(this).find('.tblinput.semails.txtInputta.pvar').val('');
});
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.