例如:user - 输入 123 值为 - www.helloneed 123 help.com提交
来自网址的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>
任何想法? sheraz
答案 0 :(得分: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>
答案 1 :(得分:0)
只需在输入标记中添加'onclick'事件并在其中编写javascript代码即可。
<input type="submit" name="submit" value="submit" class="submit" onclick="post.value='www.helloneed' + post.value + 'help.com';" />
答案 2 :(得分:-1)
您可以尝试预先添加&amp;将文本附加到输入框的值。
e.g。 onsubmit =“$('#post')。。('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>
(在你第一次测试之后,我会删除返回的假文本)
安德鲁
答案 3 :(得分:-1)
无法在HTML中执行此操作。这些问题应该在服务器端处理。
很容易在JavaScript中执行此操作,如iambriansreed的答案中所述,但它在服务器端执行它同样简单且更加健壮。在这种情况下,甚至不需要在客户端也这样做;它会使事情变得复杂,因为服务器端代码没有直接的方法来知道它得到了什么(直接用户输入与客户端JavaScript在启用时修改的输入)。