我有一点javascript可以找到一个现有的id并用表单替换它。Javascript - 将变量添加到表单中提交
在该表单中,我希望能够将JavaScript变量添加到提交网址。我不确定这是可能的,或者我只是错误地实施它。
$(document).ready(function() {
$("#FB_cs_redirectTextBox")
.replaceWith('<form class="cf" action="http://test.com/s/search.html?profile=_default&collection=general + document.getElementById(' + item-select + ').value" method="get">' +
'<input type="search" placeholder="Search for stuff" name="search" class="searchbox-input" required="">' +
'<select name="item-select" id="item-select" required="">' +
'<option value="" selected="selected">Item type...</option>' +
'<option value="level">item 1</option>' +
'<option value="taste">item 2</option>' +
'<option value="location">item 3</option>' +
'<option value="month">item 4</option>' +
'</select>' +
'<button type="submit" class="btn btn--green searchbox-submit">' +
'Search for items' +
'</button>' +
'</form>');
});
所以这是我的问题我行认为:
action="http://test.com/s/search.html?profile=_default&collection=general + document.getElementById(' + item-select + ').value"
我也想知道,如果这是可能的,我怎么也选择的值添加到URL操作。我是否会通过将相同的ID应用于所有选项然后调用该ID名称上的document.getElementById来执行此操作?
所有帮助非常感谢!
可能重复:http://stackoverflow.com/questions/993834/adding- post-parameters-before-submit – Vikash
“action”的期望网址之一是什么?就像'http://test.com/s/search.html?profile = _default&collection = generallevel'? – Xufox
哎呦错过了一点,它应该是:http://test.com/s/search.html?profile=_default&collection=general&search=然后在这里修改的变量 – hlh3406