我的语法如下:
$("#orderbynumber").autocomplete(
{
source: "get_orders_by_order_number",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
alert(selectedObj.value);
//get prices
$.post('get_sku_prices', {data:selectedObj.value},function(result) {
$('input[name^="deliveryweek"]').val(result[0]);
});
}
});
警报返回order number: Customer Name
,例如10827: Massmart
我想要做的是从: Massmart
剥离selectedObj.value
所以我想要一个新变量(例如)selectedobjectorder = 10827
然后我可以将此订单号作为get_sku_prices
函数传递给它。
如下所示:
$("#orderbynumber").autocomplete(
{
source: "get_orders_by_order_number",
messages:
{
noResults: '',
results: function() {}
},
select: function( event, ui )
{
var selectedObj = ui.item;
alert(selectedObj.value);
//how to finx this code...
var selectedobjectorder= anything before :(selectedObj.value);
alert(selectedobjectorder);
//get prices
$.post('get_sku_prices', {data:selectedobjectorder},function(result) {
$('input[name^="deliveryweek"]').val(result[0]);
});
}
});
一如既往地谢谢。
答案 0 :(得分:1)
JS parseInt()就是你想要的。
var selectedobjectorder = parseInt(jQuery.trim(selectedObj.value));