English 中文(简体)
偷窃选择。 B. 离职后的变化
原标题:Stopping select.change from posting back

这个问题是更大篇幅的一部分,但我简化了该法典,以提供我所谈论的简单例子。 从根本上讲,我有一个与“AutoPostBack=“true”合作的协会退席名单,我想做一些 j门客户,必要时可以停止退席。 然而,我可以阻止退席。

<script type="text/javascript">
$(document).ready(function()
{
    $("#ddl").bind( change , function() {
        return false;
    });
});
</script>

<select id="ddl" onchange="form.submit()">
    <option value="">Item 1</option>
    <option value="">Item 2</option>
    <option value="">Item 3</option>
    <option value="">Item 4</option>
    <option value="">Item 5</option>
</select>
最佳回答

这是我的工作(Firefox工程,IE 7/8工程):

$(function() {
    var $select = $( #ddl ), tmp = $select.attr( onchange );

    $select.attr( onchange ,   );

    $select.change(function() {
        // If you want to postback:
        tmp();
    });
});

简单删除了超文本手稿,使之变成一个变数。 然后,你可以登记您的变更职能,如果你希望把自动退职职能称作你的话。

问题回答
$("#ddl").change(function(e) {
    e.preventDefault();
});

为此:

$(document).ready(function() {
  $( #ddl ).attr( onchange ,   ).change(function() {
    if (0 !== +$(this).attr( selectedIndex )) {
      this.form.submit();
    }
    return false;
  });
});
$("#ddl").change(function() {
    // Do some javascript
    return false;
});

此外,如果你在选择要素之外作出保留,这也会有所帮助。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签