使用jquery获取输入按钮的值 [英] get value for a input button using jquery

查看:62
本文介绍了使用jquery获取输入按钮的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用jquery检索可点击按钮的值。我在< div> 下有3个按钮。

i need to retrieve value for a clickable button using jquery. i have 3 buttons under a <div>.

<div class="button1">
        <input type="button" value="one" id="One" onclick= "location.href='index.html'"/> 
        <input type="button" value="two" id="Two" onclick="location.href='index.html'" />
        <input type="button" value="three" id="Three" onclick="location.href='index.html'" />
 </div> 

如果我点击按钮1我需要获得按钮1的值。我不知道如何获得这个价值。

if i click on button 1 i need to get value for a button 1. i dunno how exactly get the value of this.

这是我的js。

$(document).ready(function() {
    $('.button1').click(function() {
        var text = $(this).text();
        $("input").val(text);
        });
});

我知道这个js脚本我写错了。因为我的价值是一,二,三。

i know this js script i wrote as wrong. because am getting values as "one,two,three".

提前感谢。

推荐答案

像任何其他输入一样,要获取按钮的值,请使用.val():

Like any other input, to get the value of a button use .val():

$('input:button').click(function() {
    alert($(this).val());
});​

http://jsfiddle.net/3QDM5/

我不确定你的脚本到底在做什么!

I'm not sure exactly what you're trying to do with your script though!

这篇关于使用jquery获取输入按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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