开发者

Get value from hidden field after append - jQuery

开发者 https://www.devze.com 2023-01-04 13:02 出处:网络
When #sw is clicked, I need alert(dc); to be triggered <form name=\"sc\" action=\"\" method=\"\">

When #sw is clicked, I need alert(dc); to be triggered

<form name="sc" action="" method="">
<div class="si" id="seli" style="position:absolute; left:15px; top:200px; width:260px;">
<select>
<?  do { $k = $row_w['k']; ?>
<option value="<? echo $k1; ?>"><? echo $1k; ?></option>
<? } while ($row_kw = mysql_fetch_assoc($kw)); ?>
</select>

<input type="submit" value="save" />
</div>
<input type="hidden" id="dc" class="dct" value="5"/>
<div id="sw" style="cursor:pointer;"></div>
</form>

and the jquery code

$('#sw').bind('click',function(e) {

 开发者_开发问答                                                var x = (e.target.id);

                                                 var y = x.substr(5,1);
                                                 var dn = ($(e.target).text());
                                                 var x1 = '<div class="s" id=s'+y+' style="margin-bottom:3px; text-align:left; border-bottom:#cccccc solid thin;">'+do_nm+'</div>';

                                                 $('.si').append(x1);
                                                 $('#'+x).fadeOut('slow');

                                                 var dc1= ('#dc').val();
                                                 alert(dc);

                                                 });

Thanks Jean


I think you're almost there. I not completely sure of the question, but if you replace:

var dc1= ('#dc').val();
alert(dc);

with:

var dc = $('#dc')[0].value;
alert(dc);

You must use [0] because jQuery's $() returns a collection of items, and the collections does not have a value property, but the instance in the collection does.


Replace

var dc1= ('#dc').val();
  var dc1= ('#dc').val();
 alert(dc);

with

 alert($('#dc').val());


you've got a typo in there

var dc1= ('#dc').val();
alert(dc);

make it

var dc = $('#dc').val();
alert(dc);

also: be sure that the id is unique in your dom! otherwise you might want to work with your class:

var dc = $('.dct').val();
alert(dc);
0

精彩评论

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