我有一个jquery应用程序,我需要根据表中存在的行数来评估表单中的变量。
所需的行为是找到产品的选定选项,拉出值(然后根据变量名称对应于预定义的价格),然后对价格做一些事情。我在评估变量名称,转换为数字,然后使用货币插件转换为货币时遇到问题。
以下是表格:
$(document).ready(function() {
var max_fields = 20; //maximum input boxes allowed
var min_fields = 6; //minimum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var ordertot = 0;
var indbrandcost = 5;
var shaftprice = 0;
$(".toproduct, .indmsg").on('keyup keypress blur change paste cut', function(){
var id28 = 25; //dynamically written based on item price
var id29 = 50;
//loop through all fields, check if that row exists, then see which selection matches up with id28 or 1d29 above, then do something
for(i = 1; i < max_fields; i++) {
if($('#toproduct'+i).val() != '') {
var f = $('#toproduct'+i).find('option:selected').attr('value');
if($('#indmsg'+i).val() != '') {
$('#unitprice'+i).text((eval('id'+f)+5).currency()); //getting error here
//var shaftprice = shaftprice + indbrandcost;
}
else {
$('#unitprice'+i).text((eval('id'+f)).currency()); // getting error here
}
}
}
});
我写的jquery如下:
public bool UpdateMethod(string param1,string param2,string key)
{
SqlCommand cmd = new SqlCommand("update [yourTableName]set field1=@param1,field12=@param2 where key=@param3", con);
cmd.Parameters.AddWithValue("@param1", param1);
cmd.Parameters.AddWithValue("@param2", param2);
cmd.Parameters.AddWithValue("@param3", key);
return Convert.ToBoolean(cmd.ExecuteNonQuery());
}
答案 0 :(得分:1)
您的代码中存在一些错误。我创建了一个有效的codepen:https://codepen.io/pahund/pen/xqpByN?editors=1011
相关代码:
$(".toproduct, .indmsg").on('keyup keypress blur change paste cut', function() {
var id28 = 25; //dynamically written based on item price
var id29 = 50;
//loop through all fields, check if that row exists, then see which selection matches up with id28 or 1d29 above, then do something
for (var i = 1; i < max_fields; i++) {
var f = $('#toproduct' + i).val();
if (f) {
if ($('#indmsg' + i).val() !== '') {
$('#unitprice' + i).text((eval('id' + f) + 5)); //getting error here
} else {
$('#unitprice' + i).text((eval('id' + f))); // getting error here
}
}
}
});