I have an h开发者_JAVA百科idden input:
<input type="hidden" id="hidden" />
$('#hidden').before('<input type="text" id="mhidden" alt="decimal" value="" />');
var val = $('#hidden').val();
$('#mhidden').val(val);
In <input type="text" id="mhidden" alt="decimal" value="" />
the value is empty in html but with alert($('#mhidden').val(val));
has a value. Why the value of #mhidden is empty? I want to assign hidden input's value to #mhidden.
Thanks in advance
alert($('#mhidden').val(val));
This passes the value of the val
variable to the val()
function. This function acts as a getter/setter depending on whether a parameter is passed or not. What is being alerted is the return value for the setter version, which will be the jQuery object for $('#mhidden')
.
you want to add the value of hidden to mhidden in html you can try this
var val = $('#hidden').val();
$('#hidden').before('<input type="text" id="mhidden" alt="decimal" value='+val+' />');
精彩评论