javascript 怎么给onclick 事件所调用的函数传递参数.
functiontriangleCoordschange(arr1,arr2){triangleCoords=[newgoogle.maps.LatLng(arr1[0]...
function triangleCoordschange(arr1,arr2){
triangleCoords = [
new google.maps.LatLng(arr1[0], arr2[0]),
new google.maps.LatLng(arr1[1], arr2[1]),
new google.maps.LatLng(arr1[2], arr2[2])
];
}
onclick = “triangleCoordschange(arr1,arr2)”
参数怎么传递,还有,参数在什么地方定义?我需要在text文本中获取arr1,arr2两个数组的值。怎么破? 展开
triangleCoords = [
new google.maps.LatLng(arr1[0], arr2[0]),
new google.maps.LatLng(arr1[1], arr2[1]),
new google.maps.LatLng(arr1[2], arr2[2])
];
}
onclick = “triangleCoordschange(arr1,arr2)”
参数怎么传递,还有,参数在什么地方定义?我需要在text文本中获取arr1,arr2两个数组的值。怎么破? 展开
2个回答
展开全部
一:参数分为形参和实参,function triangleCoordschange(arr1,arr2)这里面是形参,triangleCoordschange(arr1,arr2)这里面是实参,参数通过实参传到形参,triangleCoordschange(arr1,arr2)是调用函数,给此函数赋值就可以了。
二:获取参数,var arr1=document.getElementById("属性名");当然还有getElementByTagName, 这要看你代码了
二:获取参数,var arr1=document.getElementById("属性名");当然还有getElementByTagName, 这要看你代码了
追问
谢谢解答,明白了一点,有小例子吗?
展开全部
/* *
* 添加商品到购物车
*/
function addToCart(goodsId, parentId)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
var selected_num = '';
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);
if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}
quick = 1;
}
selected_num = document.getElementById("selected_num").value;
goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.selected_num = selected_num;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
Ajax.call('/flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
}
* 添加商品到购物车
*/
function addToCart(goodsId, parentId)
{
var goods = new Object();
var spec_arr = new Array();
var fittings_arr = new Array();
var number = 1;
var formBuy = document.forms['ECS_FORMBUY'];
var quick = 0;
var selected_num = '';
// 检查是否有商品规格
if (formBuy)
{
spec_arr = getSelectedAttributes(formBuy);
if (formBuy.elements['number'])
{
number = formBuy.elements['number'].value;
}
quick = 1;
}
selected_num = document.getElementById("selected_num").value;
goods.quick = quick;
goods.spec = spec_arr;
goods.goods_id = goodsId;
goods.number = number;
goods.selected_num = selected_num;
goods.parent = (typeof(parentId) == "undefined") ? 0 : parseInt(parentId);
Ajax.call('/flow.php?step=add_to_cart', 'goods=' + goods.toJSONString(), addToCartResponse, 'POST', 'JSON');
}
追问
我不知道应该怎么在onclick里面传递参数,应该怎么写?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询