- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在下图中显示了场景,这里我需要计算我的动态按钮点击发生时的价格。(批发价 * 数量 = 商品总价)
Firebug 中的错误显示是:
txtId is not defined
我在这里尝试使用 javascript 来做到这一点。
$('#pick').click(function () {
this.disabled = true;
var $option = $('#select-product option');
var table = $('<table border="0" class="table table-bordered"><th>ItemName</th><th>Retail Price</th><th>Wholesale Price</th><th>Quantity</th><th>Calculate</th><th>Total Item Price</th></table>').addClass('product-table');
var i=0;
$option.each(function () {
debugger;
if ($(this).prop('selected')) {
var txtId = 'txtQty' + i;
var lblId = 'lblQty' + i;
var row = $('<tr><td>' + $(this).text() + '</td><td>' + $(this).attr('RetailPrice') + '</td><td>' + $(this).attr('WholesalePrice') + '</td><td>' + '<input type="text" id="' + txtId + '">' + '</td><td> <button type="button" class="btn btn-warning btn-xs" onClick="CalcPrice(txtId,$(this).attr(\'WholesalePrice\'),lblId)">Calculate</button></td><td><label for="tempprice" id="lblQty' + i + '></label></td></tr>');
table.append(row);
i++;
}
});
$('#product-load-tbl').append(table);
});
function CalcPrice(txtId,prc,lblId) {
debugger;
}
最佳答案
既然你提到了
i need to Calculate the price when my dynamic button click occured
你必须像这样使用事件处理程序
$(document).on('click', '#pick', function () {
//Your code
}
因为动态生成的按钮没有加载到 DOM 中,所以您需要使用委托(delegate)。
HTML:静态
Fiddle1:
$('button').click(function () {
alert("I'm clicked");
});
$('body').append('<button>Dynamic</button>'); //button will be append
//click event won't work
fiddle 2:
$(document).on('click','button', function () {
alert("I'm clicked");
});
$('body').append('<button>Dynamic</button>'); //Will for buttons created dynamcially
关于c# - 事件中的动态按钮单击句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22653485/
我设置了 Helm 柄和 Helm 柄。我有tiller-deploy。昨天,我可以定期运行了。但今天我收到此错误消息 Error: could not find a ready tiller pod
我以前已将分er安装到特定的 namespace 中。 我设置了一个环境变量来设置'tiller'命名空间-但我不记得该环境变量的名称-而且似乎无法通过网络搜索找到它。 这是什么 key ? 最佳答案
当我在 View 模型中使用如下界面时 class MainViewModel @ViewModelInject constructor( private val trafficImagesR
我正在尝试找到如何在某个 fragment 相关场景中定义 Hilt 的解决方案。我有以下设置: Activity 父 fragment 1 子 fragment 1 子 fragment 2 ...
Hilt 指出如果没有@Provides 注解就不能提供这个接口(interface): interface PlannedListRepository { fun getAllLists()
我的问题非常简单明了:两个注释/示例之间有什么区别: 例子一 @Singleton class MySingletonClass() {} @Module @InstallIn(FragmentCom
我是一名优秀的程序员,十分优秀!