点击按钮获取输入值

时间:2013-03-06 04:56:11

标签: javascript jquery

点击input时,我想获取button的值

这是代码:

HTML:

<li class=" qq-upload-success">
    <span class="qq-upload-image">
        <img src="b50.jpg">
    </span>
    <span class="qq-upload-remover btn btn-danger">
         <a href="#"><li class="icon-trash icon-white"></i> Remover</a>
    </span>
    <input type="hidden" name="imagens[]" value="b50.jpg">
</li>

jQuery的:

$('.qq-upload-remover a').live("click", function(event){
    event.preventDefault();
    //var elem = $(".qq-upload-remover");
    //var linkrev = $(this).next().attr('value');
    //alert (linkrev);
    var linha = $(this).parent().parent().fadeOut('slow', function(){
            //$.post('acoes.php?Acao=11&AnuncioFoto_Id='+id);
            if($(".qq-upload-list .qq-upload-success:visible").length == 0){
                $(".qq-upload-list .enviar").remove();
            }
    });
});

当我点击qq-uplod-remover时,我想获得inputb50.jpg

我在同一页面上有多个li

我尝试使用qq-upload-remover点击get $(this).next().attr('value'),但它不起作用。

3 个答案:

答案 0 :(得分:2)

尝试如下,。

<script type="text/javascript">

    $(function()
    {
        $('span.qq-upload-remover a').on('click',function(e){
            //e.preventDefault(); to stop default behaviour
            //e.stopPropagation(); to stop bubbling

            alert($(this).parent().parent().find('input:hidden').val());
        });
    });

</script>

<li class=" qq-upload-success">
    <span class="qq-upload-image">  <img src="b50.jpg"></span>
    <span class="qq-upload-remover btn btn-danger">
        <a href="#">
            <i class="icon-trash icon-white"></i> Remover
        </a>
    </span>
    <input type="hidden" name="imagens[]" value="b50.jpg">
</li>

答案 1 :(得分:0)

$(".qq-upload-remover").click(function(){
   var data = $("input[name^='imagens[]']");
   $.each(data, function(key, object) {
        alert(object.value); 
   });  
});

此代码经过测试。

答案 2 :(得分:0)

试试这个:jsfiddle

$('.qq-upload-remover a').click(function(){
   alert($(this).parent().siblings('input').val());
});