【发布时间】:2018-04-28 17:32:33
【问题描述】:
我正在尝试在使用 jQuery 提交表单之前更改输入文本字段的值,如下所示:
<form actions="http://test.com/" method="GET">
<input name="test" id="autocompleteform" type="text"/>
</form>
<script>
$('#form-customer-attr-new').submit(function(e) {
var value = $("#autocompleteform").val();
value = value.substr(0, value.indexOf(' '));
if (!isNan(value) && !empty(value)) {
$("#autocompleteform").val(value);
alert($("#autocompleteform").val());
return true;
} else {
alert("Invalid Postcode");
return false;
}
});
</script>
当我提醒输入文件的值时,它显示的是新值,但是当表单提交时,url中的参数仍然显示输入的旧值,例如:
old_input_value = "1234 justice spoiler message";
new_input_value = "1234";
the_url_after_form_submit_now = "http://test.com?test=1234+justice+spoiler+message";
the_url_after_form_submit_should_be ="http://test.com?test=1234";
【问题讨论】:
-
扰流板的标志?
-
这是您的确切代码吗?因为您的表单没有此 ID '#form-customer-attr-new'。
-
@OfirBaruch 我刚刚编辑了我的问题
-
@BadMiscuit 删除了剧透 :)
标签: javascript php jquery forms textinput