Javascript 使用jQuery清除输入字段中的值
嗨,我有许多电话号码的输入,它们使用相同的类和相同的显示/隐藏技术。 我希望能够清除输入框中电话号码的内容,即输入电话的类名 然而,它似乎清除了我假设的所有输入,因为我使用了下面的行<代码>输入:text,当我把它放入一个类中时,它就是无法工作 我的JS和一些html在下面或视图a中:Javascript 使用jQuery清除输入字段中的值,javascript,jquery,html,Javascript,Jquery,Html,嗨,我有许多电话号码的输入,它们使用相同的类和相同的显示/隐藏技术。 我希望能够清除输入框中电话号码的内容,即输入电话的类名 然而,它似乎清除了我假设的所有输入,因为我使用了下面的行输入:text,当我把它放入一个类中时,它就是无法工作 我的JS和一些html在下面或视图a中: $(“.contact_numbers”)。在('click','.clearnumber',函数(){ $(this).sides('input:text').val(“”); }); 如果您正在查看my JSFID
$(“.contact_numbers”)。在('click','.clearnumber',函数(){
$(this).sides('input:text').val(“”);
});
如果您正在查看my JSFIDLE,请单击“显示其他数字”以显示“清除”按钮。
更新
我希望能够清除最近的输入电话,而不是全部,因为它们是多个数字
提前谢谢那么针对
输入电话
类如何
$(".contact_numbers").on('click', '.clearnumber', function () {
$(this).parent().parent().find('input.input_tel').val('');
});
假设没有其他输入字段上有
input\u tel
类。那么以input\u tel
类为目标如何
$(".contact_numbers").on('click', '.clearnumber', function () {
$(this).parent().parent().find('input.input_tel').val('');
});
假设没有其他输入字段具有input\u tel
类。替换:
$(this).siblings('input:text').val('');
与
$(this).siblings('input:text').closest('.input_tel').val('');
更换:
$(this).siblings('input:text').val('');
与
$(this).siblings('input:text').closest('.input_tel').val('');
这应该可以
$(".contact_numbers").on('click', function () {
$(".input_tel").val('');
});
这应该可以
$(".contact_numbers").on('click', function () {
$(".input_tel").val('');
});
使用jquery清除输入字段的安全方法
$.fn.noText = function() {/*use the jquery prototype technology to make a chainable clear field method*/
if(this.is('input')){ /*check to c if you the element type is an input*/
this.val('');/*clear the input field*/
}return this;/*means it is chainable*/
};
$('input').noText();
使用jquery清除输入字段的安全方法
$.fn.noText = function() {/*use the jquery prototype technology to make a chainable clear field method*/
if(this.is('input')){ /*check to c if you the element type is an input*/
this.val('');/*clear the input field*/
}return this;/*means it is chainable*/
};
$('input').noText();
这清除了整行内容我要它清除最近的输入内容不要担心将类型更改为类并替换名称清除了整行内容我要它清除最近的输入内容不要担心将类型更改为类并替换名称如果使用
parent()
然后以类为目标,如我的新编辑?如果使用parent()
升级两个级别,然后以类为目标,如我的新编辑,该怎么办?