点击ul的li中的按钮获取项目引用号码?

时间:2016-05-25 15:07:29

标签: javascript jquery html css

我有button

中的值列表和ul
<ul> 
    <li class="mix" category-1="" data-value="600.35" style="display:block;">
        <figure>
            <figcaption>
                <h3>TK</h3>
                <span>LHR</span> 
                <span>LHE</span>
                <div class="clear"></div>
                <span>Sat 28May16</span> 
                <span>
                    18:00
                    <span></span>
                    <span>
                        <i class="fa" fa-clock-o=""></i>
                    </span>
                    7361116644561201001 
                    <div class="clear"></div> 
                    <div class="price-night">
                        <span>1 Stop</span>
                        <span class="price-n">600.35 (£)</span>
                    </div>

                    <button class="info">Buy Now</button>
                </span>
            </figcaption>
        </figure>
    </li>

    <li class="mix" category-1="" data-value="600.35" style="display:block;">
        <figure>
            <figcaption>
                <h3>TK</h3>
                <span>LHR</span> 
                <span>LHE</span>
                <div class="clear"></div>
                <span>Sat 28May16</span> 
                <span>
                    18:00
                    <span></span>
                    <span>
                        <i class="fa" fa-clock-o=""></i>
                    </span>
                    7361116644561201001 
                    <div class="clear"></div> 
                    <div class="price-night">
                        <span>1 Stop</span>
                        <span class="price-n">600.35 (£)</span>
                    </div>

                    <button class="info">Buy Now</button>
                </span>
            </figcaption>
        </figure>
    </li>
<ul/>

点击button我想得到参考号,结束,总共3个值,我正在使用ASP.NET,所以我可以使用任何方法添加单个函数{{1调用但是如何获取oncick

li

2 个答案:

答案 0 :(得分:0)

你必须迭代你的项目并抓住你需要的东西,这里有你的结构的例子:

&#13;
&#13;
$(".info").click(function(se,ev)
{
  $.each($(".mix"),function(index,element)
  {
    alert($(element).attr("data-value"));
  })
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul> <li class="mix" category-1="" data-value="600.35" style="display:block;"><figure><figcaption><h3>TK</h3><span>LHR</span> <span>LHE</span><div class="clear"></div><span>Sat 28May16</span> <span>18:00<span></span><span><i class="fa" fa-clock-o=""></i></span>7361116644561201001 <div class="clear"></div> <div class="price-night"><span>1 Stop</span><span class="price-n">600.35 (£)</span></div>

<button class="info">Buy Now</button></span></figcaption></figure></li>

<li class="mix" category-1="" data-value="600.35" style="display:block;"><figure><figcaption><h3>TK</h3><span>LHR</span> <span>LHE</span><div class="clear"></div><span>Sat 28May16</span> <span>18:00<span></span><span><i class="fa" fa-clock-o=""></i></span>7361116644561201001 <div class="clear"></div> <div class="price-night"><span>1 Stop</span><span class="price-n">600.35 (£)</span></div>

<button class="info">Buy Now</button></span></figcaption></figure></li>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您的问题很难遵循,但是假设您需要在单个函数中获取单击按钮的值,这可能会有所帮助。

&#13;
&#13;
$( "ul li" ).click(function() {
  value = $(this).data("value");
  alert( value );
});
&#13;
&#13;
&#13;