Jquery Live函数在Firefox中不起作用
我的脚本代码Jquery Live函数在Firefox中不起作用,jquery,Jquery,我的脚本代码 $(function () { $(".ui-button-text").live("click", function () { var buttonName = $(this).text(); if (buttonName == 'Continue') { $("#runloGc").prop("disabled", true); } }); }); Html代码 <button
$(function () {
$(".ui-button-text").live("click", function () {
var buttonName = $(this).text();
if (buttonName == 'Continue') {
$("#runloGc").prop("disabled", true);
}
});
});
Html代码
<button type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">Cancel</span></button>
.live函数已弃用,请尝试使用:
或者试试看
$(function(){
$("input[type='button']").on("click",".ui-button-text",function(){
var buttonName=$(this).text();
if(buttonName == 'Continue'){
$("#runloGc").prop("disabled",true);
}
});
});
您应该使用以下选项:
// New way (jQuery 1.7+) - .on(events, selector, handler)
$('#container').on('click', '.ui-button-text', function(event) {
event.preventDefault();
alert('testlink');
});
这会将事件附加到容器元素中的任何锚,
减少了必须检查整个文档元素树的范围,提高了效率
这是最好的情况。如果您不确定容器元素,则可以使用文档,如下所示:
$(document).on('click', '.ui-button-text', function(event) {
根据更新的代码,应该将事件绑定到按钮,而不是范围
live已被弃用。此问题已被询问数百万次。已在jQuery 1.9中删除。它可能不起作用,因为您正在附加到按钮内跨度的click事件,并且按钮click事件很可能是触发/捕获的事件。。在chrome中也不起作用。。!!应该类似于$body.onclick、.ui按钮文本、函数{或至少$div.onclick、.ui按钮文本、函数{@ShadowWizard现在我已经添加了它,您也可以替换$input[type='button']使用$document@Omar我会服从你的……我们可以给任何文档、正文、div、按钮、输入……等等。blah blahNo Omar不使用此功能给,$.ui button.onclick,函数{};在chrome中工作而不是在firefox$document中。单击,'button.ui button',函数{在firefox最新版本21.0上测试。@SiddeshHalke@Omar它现在工作得很好。!!多谢,你让我开心。!!SiddeshHalke欢迎,很高兴帮助:
$(document).on('click', '.ui-button-text', function(event) {
$(document).on('click', 'button.ui-button', function () {
// code
});