1

我的脚本代码

$(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>
4

3 回答 3

0

.live()功能已弃用,请尝试使用.on()

$(function(){
    $(".ui-button-text").on("click",function(){
        var buttonName=$(this).text();
         if(buttonName == 'Continue'){
             $("#runloGc").prop("disabled",true);
         } 
     });
});

或尝试喜欢

$(function(){
    $("input[type='button']").on("click",".ui-button-text",function(){
        var buttonName=$(this).text();
         if(buttonName == 'Continue'){
             $("#runloGc").prop("disabled",true);
         } 
     });
});
于 2013-06-05T13:21:43.673 回答
0

您应该使用以下内容:

// New way (jQuery 1.7+) - .on(events, selector, handler)
$('#container').on('click', '.ui-button-text', function(event) {
    event.preventDefault();
    alert('testlink'); 
});

这会将您的事件附加到元素内的任何锚点#container,从而减少必须检查整个document元素树的范围并提高效率。

这是最好的情况。如果您不确定container元素,可以使用documentthen 之类的:

$(document).on('click', '.ui-button-text', function(event) {

小提琴演示

于 2013-06-05T13:31:56.837 回答
0

根据您更新的代码,您应该将事件绑定到buttonnot span.

演示

$(document).on('click', 'button.ui-button', function () {
 // code
});
于 2013-06-05T13:43:07.333 回答