0

好的,就是这样...我需要提交一个表单,用户在输入框中输入信息,但该值还有其他文本。

例如:用户 - 输入123值是 - www.helloneed 123 help.com 提交

来自 url 的 123 是用户输入的内容

这是我的代码:

<form name="postcode" method="post" action="location.html">
<input type="text" name="post" id="post" required="required"  maxlength="8" />
<input type="submit" name="submit" value="submit" class="submit" />
</form>

有任何想法吗?谢拉兹

4

4 回答 4

1

不需要 jQuery,直接使用 JavaScript。

在表单 HTML 之后直接添加以下内容:

<script>
document.forms.postcode.onsubmit = function(){    
    this.post.value = 'www.helloneed' + this.post.value + 'help.com';
    alert(this.post.value);
}​
</script>

小提琴:http: //jsfiddle.net/iambriansreed/ZeKUq/

于 2012-05-21T17:14:48.517 回答
0

只需在输入标签中添加“onclick”事件并在那里编写 javascript 代码。

<input type="submit" name="submit" value="submit" class="submit" onclick="post.value='www.helloneed' + post.value + 'help.com';" />
于 2012-05-22T06:22:40.160 回答
-1

您可以尝试在输入框的值中添加和附加文本。

例如 onsubmit="$('#post').val('http://www.helloneed' + $('#post').val() + 'help.com');

这可能有效:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<form name="postcode" method="post" action="location.html" onsubmit="$('#post').val('http://www.helloneed' + $('#post').val() + 'help.com'); return false">
<input type="text" name="post" id="post" required="required"  maxlength="8" />
<input type="submit" name="submit" value="submit" class="submit" />
</form>

(在您的第一次测试之后,我会删除返回的错误文本)

安德鲁

于 2012-05-21T17:11:32.637 回答
-1

在 HTML 中无法做到这一点。此类问题应在服务器端处理。

正如 iambriansreed 的回答中所述,在 JavaScript 中执行此操作很容易,但在服务器端执行此操作同样简单且更加健壮。在这种情况下,甚至不需要在客户端执行此操作;它只会使事情复杂化,因为服务器端代码无法直接知道它得到了什么(直接用户输入与启用时由客户端 JavaScript 修改的输入)。

于 2012-05-21T17:24:04.080 回答