<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>fir</title>
</head>
<body>
<form id="form" method = "post" action = "http://www.kuaidi100.com/query?type=yuantong&postid=postttt&id=1&valicode=&temp=123">
<label>用户名:</label>
<input type="text" value="100605028323" postttt = "" id="txt" />
<input type="submit" value="确定" name="submit" id="sub"/>
</form>
<script>
var txt = document.getElementById("txt");
var btn = document.getElementById("sub");
var form = document.getElementById("form");
console.log(typeof form.action);
btn.onclick= function () {
var action = form.action;
form.action = action.replace(/postttt/, txt.value);
}
</script>
</body>
</html>
4 回答
![?](http://img1.sycdn.imooc.com/54584802000154b602200220-100-100.jpg)
ThinkAllNight
TA贡献35条经验 获得超31个赞
可以用 ajax 或者 jsonp 方法替换 form 元素的 post方法, 具体可以采用 jQuery 的 $.get() , $.post(), $.getJSON, $.ajax()等API ,并且将页面中的form标签换成普通的div即可.
当然,你可以自己用原生 js 封装一个ajax方法,依据需求而定。
已采纳
![?](http://img1.sycdn.imooc.com/54584802000154b602200220-100-100.jpg)
ThinkAllNight
TA贡献35条经验 获得超31个赞
应该是后台没有开放端口。因为 ajax 遵守“同源策略”, 不在同一协议、域名、端口下的ajax请求一般获取不到数据,浏览器有报错,如下:
可以选择线上调试,或者跟后台协商开放端口。
- 4 回答
- 0 关注
- 1791 浏览
添加回答
举报
0/150
提交
取消