开发者

Jquery and php, load images and use the src of each image

I have a page that display a group of images with the src of each image, but I need to use the src valu of the images. The images loads correctly but when I try to load into input text the src value of the selection image it not work:

    $("#recurs").click(function(){
    $("input[name=''valReturn]").val($("rec").val());
});

the php code:

$recu= $objRecur->show_rec_project($aux["IdProject"]);
    if(!empty($recu)){
        while($row = mysql_fetch_array($recu)){
            echo'<img sr开发者_如何学编程c="'.$row["srcrecursos"].'" id="recurs"/><br />';
        }
    }else{
        echo 'No items found';
    }

And the input that need to load the src value:

<input type="text" id="valReturn" name="valReturn" width="25px"/> <br/>

The php code works but for to load the value into valReturn value not. thanks.


Try this one:

$("#recurs").click(function(){
    $("input[name=valReturn]").val($(this).attr('src'));
});

or

$("#recurs").bind("click", function(){
    $("input[name=valReturn]").val($(this).attr('src'));
});

In val use $(this) instead $("#recurs")

UPDATED

$(".recurs").click(function(){
    $("input[name=valReturn]").val($(this).attr('src'));
});

or

$(".recurs").bind("click", function(){
    $("input[name=valReturn]").val($(this).attr('src'));
});

<img src="'.$row["srcrecursos"].'" class="recurs"/>


You should do:

$("#recurs").click(function(){
    $("input[name=valReturn]").val($("#recurs").attr('src'));
});


You need:

<script type="text/javascript">
    $(function() {
        $("#recurs").click(function(){
            $("input[name='valReturn']").val($(this).attr('src'));
        }
    });
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜