簡體   English   中英

如何獲得文本框內的價值 <a></a> 使用jQuery標簽

[英]How to get textbox value Inside <a></a> tag using jquery

這是我的html代碼:

<div class="viewPopup login-popup"  id="login-box">
     <a href="#" class="close"><img src="images/close.png" class="btn_close" title="Close Window" alt="Close" /></a>
     <h6 class="h6">Task Name</h5>
     <div class="info">
      <p class="name">Assigned to </p>
      <p class="cont1"> Kumar</p>
     </div>
     <div class="info">
      <ul>
      <li><p class="name">Task </p></li>
      <li><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec condimentum est ut dolor aliquam sit amet suscipit urna vehicula. Nunc dolor massa, viverra commodo gravida sed, sodales et metus. Maecenas lacinia facilisis semper. Pellentesque ac tellus lacus.</p></li>
      </ul>

     </div>
     <div class="info">
      <p class="name">Starting Date </p>
      <p class="cont1"> 19/12/2012</p>
     </div>

     <div class="info">
      <p class="name">Ending Date </p>
      <p class="cont1"> 22/12/2012</p>
     </div>
</div>

<a href="#login-box" class="login-window" title="View">
    <input type="text" name="review_id" id="review_id" value="10" />
    <img src="images/eye.png" >
</a>
<a href="#login-box" class="login-window" title="View">
                        <input type="text" name="review_id_txt" id="review_id_txt" value="10" />
                        <img src="images/eye.png" >
                   </a>

這是我的jQuery代碼:

// JavaScript Document
$(document).ready(function() {
    $('a.login-window').click(function() {

                //Getting the variable's value from a link 
        var loginBox = $(this).attr('href');

        //Fade in the Popup
        $(loginBox).fadeIn(300);

        //Set the center alignment padding + border see css style
        var popMargTop = ($(loginBox).height() + 24) / 2; 
        var popMargLeft = ($(loginBox).width() + 24) / 2; 

        $(loginBox).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });

        // Add the mask to body
        $('body').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);

        return false;
    });

    // When clicking on the button close or the mask layer the popup closed
    $('a.close, #mask').live('click', function() { 
      $('#mask , .login-popup').fadeOut(300 , function() {
        $('#mask').remove();  
    }); 
    return false;
    });
});

在這里,我想獲取該jQuery代碼中的文本框值。

這意味着<a></a>標記中包含一個文本框review_id

所以我想通過使用`標簽來獲取文本框的值。

我知道這段代碼:

$("#review_id").val();

但是我實際上是基於<a>文本框值。

我怎樣才能做到這一點?

可能嗎?

編輯:

<?php for($i=0;$i<5;$i++){?>
<a href="#login-box" class="login-window" title="View">
                        <input type="text" name="review_ids" id="review_<?php echo $i;?>" value="<?php echo $i;?>" />
                        <img src="images/eye.png" >
                   </a>

這將創建5個<a>標簽和5個文本框。然后如何獲取review_ids文本框值...

嘗試這樣:

<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="gencyolcu" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
 $('a.login-window').click(function() {
          var valuet=   $(this).find("#review_id").val();
          alert(valuet);
});
</script>
    <title>Untitled 1</title>
</head>

<body>

<a href="#login-box" class="login-window" title="View">
                        <input type="text" name="review_id" id="review_id" value="10" />
                        <img src="images/eye.png" >
                   </a>


<a href="#login-box" class="login-window" title="View">
                        <input type="text" name="review_id" id="review_id" value="10" />
                        <img src="images/eye.png" >
                   </a>



<a href="#login-box" class="login-window" title="View">
                        <input type="text" name="review_id" id="review_id" value="10" />
                        <img src="images/eye.png" >
                   </a>


<a href="#login-box" class="login-window" title="View">
                        <input type="text" name="review_id" id="review_id" value="10" />
                        <img src="images/eye.png" >
                   </a>


</body>

</html>

嘗試一下

$(".login-window").find("#review_id").val()

JsFiddle

你錯過了夏普

$("#review_id").val();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM