url地址形式的传参格式拼接
例子一:
var gid=pid=pizi=sn=newsn=sn_price=city_id=123;
var params = 'gid=' +123;
params += '&pid=' + pid;
params += '&pizi=' + pizi;
params += '&sn=' + sn;
params += '&newsn=' + newsn; //暂时没有用
params += '&sn_price=' + sn_price;
params += '&city_id=' + city_id;
var url="product_sn.php?act=add_sn&" + params;
console.log(url);
运行结果
product_sn.php?act=add_sn&gid=123&pid=123&pizi=123&sn=123&newsn=123&sn_price=123&city_id=123
例子二:
<div class="form-div">
<form action="javascript:searchproduct();" name="addForm" id="addForm">
<!-- 分类 -->
选择城市
<select name="city" id="city" onchange="get_city();">
<option value="-1">所在城市</option>
{html_options options=$goods_city}
</select>
<select name="sn_gid" id="sn_gid" onchange="get_products();" style="width:135px;">
<option value="0">请选择商品</option>
{foreach from=$goods_list item=goods}
<option value="{$goods.goods_id}">{$goods.goods_sn} {$goods.goods_name}</option>
{/foreach}
</select>
<!-- 商品:<input type="text" name="sn_name" value="" size="12" /> -->
<select name="sn_pid" id="sn_pid">
<option value="0">请选择规格</option>
{foreach from=$products item=product}
<option value="{$product.product_id}">{$product.product_name}</option>
{/foreach}
</select>
<select name="sn_pizi" id="sn_pizi">
<option value="0">请选择坯子</option>
{foreach from=$pizi_list item=pizi}
<option value="{$pizi.title}">{$pizi.title}</option>
{/foreach}
</select>
<!-- sn_type --><input type="hidden" name="sn_type" id="sn_type" value="1" size="15" />
<!-- 半成品品号 --><input type="hidden" name="semi_sn" value="" size="5" />
<!-- 半成品品名 --><input type="hidden" name="sn_name" value="" size="5" />
成品品号<input type="text" name="sn_sn" value="" size="15" />
<!-- 新货品 --><input type="hidden" name="sn_newsn" value="" size="5" />
货品价格<input type="text" name="sn_price" value="" size="5" />
<input type="button" value="添加成品" class="button" onclick="add_sn();" />
<input type="submit" value="搜索" class="button"/>
</form>
<!-- 批量导入对应关系 -->
<!-- <form action="product_sn.php?act=batchAddGoods_relate" method="post" enctype="multipart/form-data" name="excel" target="_blank">
<input type="file" name="file" value="">
<input type="submit" value="Excel导入批量导入对应关系" class="button" />
</form> -->
<!-- 批量导入对应关系 -->
</div>
<script type="text/javascript">
//添加成品的品号
function add_sn()
{
var city_id = document.forms['addForm'].elements['city'].value; //城市id
var gid = document.forms['addForm'].elements['sn_gid'].value; //商品id
var pid = document.forms['addForm'].elements['sn_pid'].value; //规格id
var pizi = document.forms['addForm'].elements['sn_pizi'].value; //piziid
var sn = document.forms['addForm'].elements['sn_sn'].value; //product表里的sn品号
var sn_price = document.forms['addForm'].elements['sn_price'].value; //商品价格
var newsn = document.forms['addForm'].elements['sn_newsn'].value; //暂时没有用
if(city_id < 0)
{
alert('城市不能为空');
return false;
}
if(gid == '' || gid < 1)
{
alert('商品不能为空');
return false;
}
if(sn == '')
{
alert('商品成品号不能为空');
return false;
}
var params = 'gid=' +gid;
params += '&pid=' + pid;
params += '&pizi=' + pizi;
params += '&sn=' + sn;
params += '&newsn=' + newsn; //暂时没有用
params += '&sn_price=' + sn_price;
params += '&city_id=' + city_id;
var url="product_sn.php?act=add_sn&" + params;
$.get(url,function(result){
var data = result;
console.log(data);
if(data.error != 0){
alert(data.msg);
}else{
listTable.loadList();
}
},'json');
}
</script>
[Haima的博客]
http://www.cnblogs.com/haima/