【问题标题】:When I click the button ajax fonksyonu my trigger but does not trigger my click event to button当我点击按钮 ajax fonksiyonu 我的触发器但没有触发我的点击事件到按钮
【发布时间】:2016-08-05 13:21:10
【问题描述】:
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
    rel="stylesheet" type="text/css" />
<script type="text/javascript">
    $("[id*=btnSorgu]+[Onclick*=btnSorgu_Click").live("click", function () {
        $("#dialog").dialog({
            title: "",
            width: 1000,
            height: 300,
            buttons: {
                Close: function () {
                    $(this).dialog('kapat');
                    location.reload();
                }
            }
        });
        return false;
    });
</script>

功能如上所述。

<asp:Button OnClick="btnSorgu_Click" ID="btnSorgu" Text="Sorgula" runat="server" />

我的问题是;当我点击按钮 ajax fonksyonu 我的触发器但没有触发我的点击事件到按钮。

我试过这样解决,但是没有

$("[id*=btnSorgu]+[Onclick*=btnSorgu_Click").live("click", function ()

$("[id*=btnSorgu]+[Onclick*=btnSorgu_Click").live("click",OnClick, function ()

【问题讨论】:

  • 你为什么使用旧的jquery??我会尽快更新。 Live 很久以前就被弃用了 :)
  • fonksyonu 是什么?
  • @FrankerZ 提出重要问题...我只是用脏话代替了它,这句话按我的预期工作:)
  • @Furtiro 但他正在使用 .live(同样不推荐使用 .on),它解释了动态添加的内容。您的解决方案将删除它。我们不知道按钮是如何添加的。
  • @Botonomous 你是对的!如果它不符合操作的需要,我会压制我的答案:)

标签: c# jquery asp.net .net


【解决方案1】:

像这样改变你的按钮:

<asp:Button OnClientClick="btnSorgu_Click()" ID="btnSorgu" Text="Sorgula" runat="server" />

然后直接用javascript写你的函数:

function btnSorgu_Click()
{
     $("#dialog").dialog({
        title: "",
        width: 1000,
        height: 300,
        buttons: {
            Close: function () {
                $(this).dialog('kapat');
                location.reload();
            }
        }
    });
    return false;
    }

【讨论】:

    【解决方案2】:

    如果你使用 jQuery,你需要把你所有的代码都包装在里面

    $(function (){
    
    });
    

    点击按钮,

    你可以有这样的按钮:

    <button id="buttonid">Click Me</button>
    
    $("#buttonid").click(function (e){
    e.preventDefault(); //prevents the default action of the button. Remove if not needed.
    //event to execute when button is clicked.
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-06
      • 2016-07-01
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多