我正在尝试使用 JavaScript 或 jQuery 创建 URL 生成器表单。
基本上,它将获取两个表单字段的值,将它们添加到预设 URL 并在提交时将其显示在第三个字段上。
结果 URL 可能是
现在,这不是表单的“操作”,应用程序无法读取 URL(以获取变量),因此必须在页面上完成。
生成的 URL 将显示在名为“url”的字段中。
以下是表格示例:
<form id="form1" name="form1" method="post" action="">
<p>
<label>Variable 1
<input type="text" name="variable1" id="variable1" />
</label>
</p>
<p>
<label>Variable 2
<input type="text" name="variable2" id="variable2" />
</label>
</p>
<p>
<label>URL
<input type="text" name="url" id="url" />
</label>
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
</p>
</form>
jQuery 有连载 http://api.jquery.com/serialize/它构建查询字符串值。
因此,如果您想完成整个表格:
alert($("#form1").serialize());
如果您只想执行几个字段,则只需让选择器选择这些字段即可。
alert($("#variable1, #variable2").serialize());
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)