English 中文(简体)
如何利用 j或javascript获得Droopdown的原始物品
原标题:How to get previuos item of Dropdown using jquery or javascript

I want to get the previously selected value of a dropdown control using jquery or javascript. How can i get this? I tried with prev() selector of jquery but failed

$(ddlStatus).find("option").prev(":selected").attr("text");

如果 ddlStatus有A、B、C、D、E等物品,如果选择B页的载荷,但当用户改变项目(请说)E时,我想先选择的是B。

最佳回答

你们可以这样做(不是优化,而是发挥作用):

$(document).ready(function(){
   $(ddl).data( lastSelected , $(ddl).val());
});
$(ddlstatus).change(function(){
   var lastSelected = $(this).data( lastSelected );
   $(this).data( prevLastSelected , lastSelected);
   $(this).data( lastSelected , $(this).val());
});

然后,为了了解先前选定的任何时间,你才:

var previouslySelectedValue = $(ddl).data( prevLastSelected );

对这一法典的好坏之处在于,国家得到了保留,而 均使用全球瓦尔品,因此可以适用于任何选定的箱子。

希望这一帮助。 卡车

问题回答

选择时,可节省价值。 在一次新的甄选中,在你完成之前,你将节省原有价值。

你们不能这样做,因为你是在历史信息之后,否则就没有时间。

here is a example:

HTML:

<select id="myselect">
  <option value="one" selected="selected">one</option>
  <option value="two">two</option>
  <option value="three">three</option>
</select>

JQUERY:

var prev = null; //global
var cur = $( #myselect ).val();//global
var flag = true;// global

$( #myselect ).change(function() {
    if (flag) {
        prev = cur;
        cur = $(this).val();
        flag = false;
    } else {
        prev = cur;
        cur = $(this).val();
    }
});




相关问题
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!