开发者

Attaching a jquery function to some textboxes

开发者 https://www.devze.com 2023-01-02 07:16 出处:网络
I am a newbie to jquery and need a little help. I have created the below function which does what I want it to however when I select a textbox every other textbox are automatically selected. How do I

I am a newbie to jquery and need a little help. I have created the below function which does what I want it to however when I select a textbox every other textbox are automatically selected. How do I change it and pass a parameter from the textbox so only the selected textboxes css changes on focus and blur?

   <script language="javascript" type="text/javascript">
   $(function () {
       $('.myTextBox').focus(function () {

           $('.box.textbox').addClass("active");
       }).blur(funct开发者_如何学Cion () {
           $('.box.textbox').removeClass("active");
       });
   });
</script>


Try with:

   $(function () {
   $('.myTextBox').focus(function () {

       $(this).addClass("active");
   }).blur(function () {
       $(this).removeClass("active");
   });

});


You want to update the object that fired the event so try;

  $(function () {
       $('.myTextBox').focus(function () {
           $(this).addClass("active");
       }).blur(function () {
           $(this).removeClass("active");
       });
   });


Answer for:"Thank you. On my input what do I need to put as the function takes care of both focus and blur <input id="Text1" type="text" attachhow="?" />"

You should add $(document).ready.

Add call it after you html:

<html>
     <%--  <div class="box textbox" style="width: 300px;">
        <div class="topcorners">
            <div>
                <div>
                </div>
            </div>
        </div>
        <div class="middle">
            <div class="left">
                <div class="right">
                    <input type="text" tabindex="1" maxlength="70" size="22" style="width: 292px;" class=" tbox"
                        id="email1" name="email1"/>
                </div>
            </div>
        </div>
</html>

<script type="text/javascript">
    $(document).ready(
    $(function () {
       $('.myTextBox').focus(function () {

           $(this).addClass("active");
       }).blur(function () {
           $(this).removeClass("active");
       });
    );
</script>


sorry to be a real nob. My input looks like this

 <input type="text" tabindex="1" maxlength="70" size="22" style="width: 292px;" class="myTextBox" 
                id="email1" name="email1"/>

When the textbox gets focus or blur occurs, Then the function changes my div class=" not the actual textbox

0

精彩评论

暂无评论...
验证码 换一张
取 消