簡體   English   中英

如何在jquery函數中獲取文本框值?

[英]how to get textbox value in jquery function..?

我正在嘗試為jquery函數中的循環獲取不同的文本框值。

我的PHP代碼:

<?php
        $qstid =  $addnew334->id;
        $dd = DB::table('tbltplatematerial')->where('qteid',$qstid)->get();
        foreach($dd as $d1)
        {

        $ing_id = $d1->id;
    ?> 

  <tr>
    <td><?php echo $d1->name;?></td>
    <td><input type="text" name="txtingprice" id="<?php echo $ing_id;?>" value="" ></td>
    <td><input type="checkbox" value="<?php echo $d1->id; ?>" onClick="addpriceing(<?php echo $ing_id; ?>,<?php echo $qstid;?>,<?php echo $value;?>,<?php echo $value11;?>)" id="checkid"></td>

     <?php 
        }
    ?>

我的jQuery函數:

    function addpriceing(ing_id,qstid,user_product_id,temp_id)
    {
            var price =  $("input[name='txtingprice']").val();
            alert(price);
            $.ajax({
            url: '<?= URL:: to('addpriceing1') ?>',
            type: 'GET',
            //dataType: "json",
            async : false,
            data:{
                    'price':price,
                    'ing_id':ing_id,
                    'qstid':qstid,
                    'user_product_id':user_product_id,
                    'temp_id':temp_id,

                  },
            success: function(e)
             {
                if(e == 0)  
                {
                    console.log("Successs");
                    alert("success");
                }
                else
                {
                    alert('error');
                }
             }
        });

    }

我試圖在jquery函數中獲取所有txtingprice值。 請幫忙。

由於您要使用foreach創建多個文本框,因此請使用name="txtingprice[]"代替name="txtingprice" name="txtingprice[]" 另外,您還需要在字段名稱上循環以獲取值為:

var price = $('input[name="txtingprice[]"]').map(function(){
       return this.value
   }).get()
   alert(price);

工作演示

<asp:TextBox runat="server" ID="reporting_person_name"></asp:TextBox >

string getValue=$('[id$=reporting_person_name]').val();
alert(getValue);

暫無
暫無

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

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