问题
I have a normal hidden
Input field
where I am generating random
string
. I need that to be appended to the URL where I am trying to post data to another page.
I have done this and works pretty well.
url:'Upload.html?field1=newvalue',
This is my hidden input field
<input type="hidden" id="randomdirectory"/>
Now instead of newvalue
in the query string
I need to pass my random directory value
.
回答1:
easily accomplished just do the following
var value = $("#randomdirectory").val();
url:'Upload.html?field1='+value ,
thats it ..
回答2:
Just give a name to the hidden field.
<input name="field1" type="hidden" id="randomdirectory" value="randomvalue"/>
回答3:
url: 'Upload.html?field1='+$("#randomdirectory").val()
回答4:
If I got your question right and the ID is randomly generated then you need something of this type:
url: 'Upload.html?field1=newvalue&field2=' + $('[type="hidden"]').val();
回答5:
Assuming that this is a parameter to an ajax call (as others already have), a slightly better practice is this:
url: 'Upload.html',
data: { field1: $('#randomdirectory').val() }
This will ensure that your query string is URL encoded properly (jQuery handles it for you).
来源:https://stackoverflow.com/questions/10144837/pass-hidden-field-value-using-jquery