使用 jQuery $('
当我单击带有 .canActivate
类的按钮时,它会将我带到指定的 div
并显示该按钮。但是,如果我单击返回并单击相同的按钮(或具有相同类别的另一个按钮),它只会显示一个空按钮。问题是什么?
我有以下代码:
$('.canActivate').live('vclick', function (event) {
$('#lblServiceName').text($(this).html());
$('#lblServiceId').text($(this).attr('data-serviceId'));
$('#lblServiceSubId').text($(this).attr('data-serviceSubId'));
$('#lblServicePrice').text($(this).attr('data-price'));
$('#wrapperServiceButtonDiv').empty();
$('<button type="button" id="btnActivateService" value="Activate" />').appendTo('#wrapperServiceButtonDiv');
$.mobile.changePage('#serviceDetailsDiv', 'slide', true, true);
});
When I click a button with the .canActivate
class it takes me to the designated div
and shows the button. However if I click back and click the same button (or another button with the same class for that matter) it only shows an empty button. What is the problem?
I have the following code:
$('.canActivate').live('vclick', function (event) {
$('#lblServiceName').text($(this).html());
$('#lblServiceId').text($(this).attr('data-serviceId'));
$('#lblServiceSubId').text($(this).attr('data-serviceSubId'));
$('#lblServicePrice').text($(this).attr('data-price'));
$('#wrapperServiceButtonDiv').empty();
$('<button type="button" id="btnActivateService" value="Activate" />').appendTo('#wrapperServiceButtonDiv');
$.mobile.changePage('#serviceDetailsDiv', 'slide', true, true);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您的活动看起来有问题。您有:
而且我确信您的意思是:
通过空按钮,我假设您的意思是其中没有文本。这是因为您创建了一个空按钮,其中包含以下行:
如果您想要在其上添加标签,请使用:
由于您没有发布 HTML,所以我不明白为什么它在第一次单击时起作用。
另外,您可以通过将按钮添加链接到空来保存查找:
First, your event looks wrong. You have:
And I'm sure you mean:
By empty button, I'm assuming you mean no text in it. That is because you created an empty button with the line:
If you want a label on it, use:
Since you didn't post your HTML, I can't see why it worked on the first click.
Also, you can save a lookup by chaining the button add to the empty: