开发者

How to pass parameter to another page in jquery

开发者 https://www.devze.com 2023-02-18 17:13 出处:网络
$(document).ready(function() { $userid=$(\'#imguserid\'); $(\'#files\').html(\'<a href=\"displayimage.php?uid=\'+$userid+\'\" alt=\"\" /><br />\')
$(document).ready(function()
{
  $userid=$('#imguserid');
  $('#files').html('<a href="displayimage.php?uid='+$userid+'" alt="" /><br />')
});

please somebody help me out. I can't carry parameter w开发者_StackOverflowhen I display html output in jquery.

Thanks


When you use $userid=$('#imguserid'); you add the jQuery wrapper of the given object to the $userid variable. If this is the id of a hidden input field, try .val().

$userid = $('#imguserid').val();

Why there was not added to the html code, is because, the jQuery wrapper was casted to an empty string.

Also your anchor tag is not good to display an image, Try this instead:

$('#files').html('<img src="displayimage.php?uid='+$userid+'" alt="" /><br />');

UPDATE: Edited above part, figured out what you may wanted to do :)


$(document).ready(function(){
    $userid=$('#imguserid');
    $('#files').html('<a href="displayimage.php?uid='+$userid+'" alt="" /><br />')
});

The document.ready is looking for an id named imguserid. It sets the value of the variable $userid equal to a reference to this id (a reference to an id usually comes back as object object).

Now the id with a name of files is selected to have it's html changed to:

<a href="displayimage.php?uid='+$userid+'" alt="" /><br />.

This html is an incomplete anchor to displayimage.php?uid= with an empty alt. The </a> is missing from the string. The reference is probably not what you want.

What parameter is it you are trying to carry?

0

精彩评论

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

关注公众号