How to get a value of jquery variable [closed]

2020-05-09 18:29发布

Jquery Code:

<script>
     $(document).ready(function() {
        var ma = $("#qty").val();
        var str = $("#reqid").val();
        $("#myform").validate({
            rules: {
                issue_quant_str: {
                    max: ma
                }
            }
        });
    });​
</script>

HTML:

<table>
    <tr><td><?php echo $array['item_name']; ?></td>
    <td><?php echo $array['quantity']; ?></td>
    <input type="hidden" value="<?php echo $array['requisition_id']; ?>" id="reqid" /> 
    <td>
        <div id="maxdiv">
            <input type="text" name="issue_quant_<?php echo $array ['requisition_id'];?>" value="<?php echo $array['quantity']; ?>" />
        </div>
    </td>
    <input type="hidden" value="<?php echo $stock_qty; ?>" id="qty" /> 
    <td><?php echo $stock_qty;?></td>
    <td><input type="text" name="rem_<?php echo $array['requisition_id'];?>" required/></td>
</tr>
</table>

Here I want var str value to be concatenated with issue_quant.I am not getting str value.Can anyone help me out..

标签: jquery
2条回答
狗以群分
2楼-- · 2020-05-09 18:46
var rules = {};
rules['issue_quant_' + str] = {max:ma};
$("#myform").validate({
    rules: rules
});
查看更多
看我几分像从前
3楼-- · 2020-05-09 19:04

try var str=$("#reqid").text();

provided that your reqid lives in your html code and has some value inside

查看更多
登录 后发表回答