Javascript 如何在一个函数中设置多个id
我在jquery中有两个函数,如下所示:-Javascript 如何在一个函数中设置多个id,javascript,jquery,Javascript,Jquery,我在jquery中有两个函数,如下所示:- $('#age').on('keypress', function(evt) { var charCode = (evt.which) ? evt.which : event.keyCode; return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)); }); $('#phone').on
$('#age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('#phone').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('#age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
$('#phone')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
此拖曳功能与此相同
所以我需要在一个函数中测量这两个函数:-
$('#phone') + $('#age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone')+$('age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
像这样:只是为了演示:
可以用逗号组合多个选择器
此链接将为您提供更多信息:
希望有此帮助:)
代码
$('#phone,#age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
您可以指定任意数量的选择器组合为一个选择器
后果这种多表达式组合器是一种有效的
选择不同的元素。中DOM元素的顺序
返回的jQuery对象可能不相同,因为它们将在
文件顺序。此组合符的另一种选择是.add()
方法
就像这样:只是为了演示: 可以用逗号组合多个选择器 此链接将为您提供更多信息: 希望有此帮助
:)
代码
$('#phone,#age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
您可以指定任意数量的选择器组合为一个选择器
后果这种多表达式组合器是一种有效的
选择不同的元素。中DOM元素的顺序
返回的jQuery对象可能不相同,因为它们将在
文件顺序。此组合符的另一种选择是.add()
方法
试试这个
$('#phone,#age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
试试这个
$('#phone,#age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
jQuery通常用于集合。可以传递多个由逗号分隔的选择器表达式。这将按照您的要求工作
$('#phone, #age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
jQuery通常用于集合。可以传递多个由逗号分隔的选择器表达式。这将按照您的要求工作
$('#phone, #age').on('keypress', function(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
return !(charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57));
});
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
您只需在选择器中使用,
即可拥有多个选择器
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
您只需在选择器中使用,
即可拥有多个选择器
$('phone,'age')。打开('keypress',函数(evt){
var charCode=(evt.which)?evt.which:event.keyCode;
返回!(charCode!=46&&charCode>31&&charCode<48|charCode>57);
});
给两个元素相同的类并按其类选择它们,然后对两个元素执行相同的操作。给两个元素相同的类并按其类选择它们,然后对两个元素执行相同的操作。Bruvo@undefined:)
祝贺60 K分!很高兴一如既往地见到你!Bruvo@undefined:)
恭喜你拿下60千分!很高兴一如既往地见到你!