根据name属性调用按钮点击事件 [英] Call the button click event based on name property

查看:45
本文介绍了根据name属性调用按钮点击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HTML 按钮,例如

<input type="button" id="btnSubmit" name="btnName" class="btnclass" value="Click Me" />

我想根据 id 属性调用 jQuery button click 事件意味着,我们使用这样的代码,

I want to call jQuery button click event based on id property means, we use the code like,

$("#btnSubmit").click(function(){ 
    ////////
});

以及基于class属性调用按钮点击事件意味着,我们使用这样的代码,

as well as call button click event based on class property means, we use the code like,

$(".btnclass").click(function(){
    /////////
});

我的问题是,我想根据 name 属性调用 button click 事件,该怎么做?

and my question is, I want to call the button click event based on name property means, How to do this?

推荐答案

您可以使用该特定元素的 name 属性.例如,要在名称为 xyz 的输入元素周围设置 2px 的边框,您可以使用;

You can use the name property for that particular element. For example to set a border of 2px around an input element with name xyz, you can use;

$(function() {
    $("input[name = 'xyz']").css("border","2px solid red");
})

演示

这篇关于根据name属性调用按钮点击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆