jQuery在选择单选按钮时更改输入文本 [英] jQuery Change Input text upon selection of radio button

查看:63
本文介绍了jQuery在选择单选按钮时更改输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试获取<input class="box" type="text" value="??" name="searchQuery"的值=",以在选择单选按钮时进行更改.因此,例如,如果用户按下名字"单选按钮,它会将.box输入的值更改为诸如输入名字"之类的值,并且也将其用于其他单选按钮.

Trying to get the value="" of <input class="box" type="text" value="??" name="searchQuery" to change upon selection of a radio button. So if the user presses 'first name' radio button for example, it changes the value of .box input to a value such as "Enter a first name" and have it do it for the other radio buttons as well.

任何人都可以帮忙吗? jQuery新手在这里:)

Can anyone help? jQuery novice here :)

<!DOCTYPE html>
<html>
<head>

    <link rel="stylesheet" href="global.css"  media="screen" />
    <link rel="stylesheet" href="design.css"  media="screen" />
    <style type="text/css">
    .hidden {
    display: none;
    }
    </style>
    <script type="text/javascript" src="inc/jquery.js"> </script>
    <script type="text/javascript">$(function() {$('input[type=text]').focus(function() {$(this).val('')});});</script>
    <!-- // -->
**<script>
    $("#searchSelect").change(function () {
          var str = "";
          $("radio option:option1").each(function () {
                str += $(this).text() + " ";
              });
          $("div").text(str);
        })
        .change();
</script>**
</head>

<body>
<div id="top_wrapper_bg">
    <div id="wrapper_top">
        <div id="header">
                <div id="logo">
                <a href="index.php"><img src="img/logo-02-01-11.png" alt="logo-02-01-11" width="300" height="100" border="0" /></a>
                </div><!-- /logo -->
                <div id="header_image">
                right
                </div><! -- /header_image -->
                <div id="clear"> </div><! -- /clear -->
                <div id="nav">
                nav
                </div><! -- /nav -->
        </div><!-- /header-->
    </div><!-- /wrapper_top -->
</div><!-- /top_wrapper_bg -->

<div id="header_search_break"> </div>

<div id="bot_wrapper_bg">       
    <div id="wrapper_bottom">
            <div id="search"> 
                    <span class="medfont">Search by:</span> 
                        <form id="searchSelect" action="#">
                            <input type="radio" name="option1" value="First Name" />First Name&nbsp;
                            <input type="radio" name="option1" value="Last Name" />Last Name&nbsp;
                            <input type="radio" name="option1" value="Department" />Department&nbsp;
                            <input type="radio" name="option1" value="Course" />Course
                        </form>
                        <br>            
                    <input class="box" type="text" name="searchQuery" value="Select an option..." class="textField clearMeFocus" />
            </div><!-- /search -->
            <div id="latest_stats">
            <p>Stats</p>
            </div><!-- /latest_stats -->
            <div id="clear"> </div>
        <div id="contain_stats">
                <div id="latest_prof">
                latest prof
                </div><!-- /latest_prof -->

                <div id="top_prof">
                top prof
                </div><!-- /top_prof -->
                <div id="clear"> </div><! -- /clear -->
        </div><!-- /contain_stats -->
        <br><br><br><br><br><br><br><br>

        <h6 style="margin:0; padding:0; font-size:0.3em;"><a href="prof.php">Prof Page</a></h6>

    </div><!-- /wrapper_bottom -->
</div><!-- /bot_wrapper_bg -->
</body>
</html>

推荐答案

<script type="text/javascript">
    $(document).ready(function(){
        $('#searchSelect input[type=radio]').change(function(){
            $('input.box').val('Enter ' + $(this).val());
        });

    });
</script>

这篇关于jQuery在选择单选按钮时更改输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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