首页 > 解决方案 > 如何在 HTML 选择列表中检索选项项的属性?

问题描述

我试图获得两个值。一方面,它正在工作,但另一方面却没有。这是我的代码:

<div class="product-price">
    <div class="lefts-column">
        <span>₹&lt;/span>
        <span id="priceval"> {{$weights[0]->price}} </span>
        <input type="hidden" class="priceval1" value="{{$weights[0]->id}}" id="pro_ids">
    </div>

    <div class="choose-weight">
        <!-- original reads <select onchange="yes(this.value,this.data)"> -->
        <select onchange="yes(this.value,this.name)">
            @foreach($weights as $weight)
            <option id="red" name="{{$weight->id}}" data-id="{{$weight->id}}"
                    class="weight" value="{{$weight->price}}">
                {{$weight->weight}}
            </option>
            @endforeach
        </select>
    </div>
</div>

<!--jquery function-->
<script>
function yes(pid , uid)
{
    $('#priceval').html(pid);
    alert(uid);
    //$('#pro_ids').val(uid);
}
</script>

现在我alert用来检查值是否被检索(然后警报什么也不显示)。

this.value正在工作,this.name但没有。有什么办法可以解决吗?

标签: phphtmljquery

解决方案


推荐阅读