English 中文(简体)
如何防止重复项目
原标题:how to prevent duplicate item

i have a dropdownlist (asp.net control) and a listbox control and a Add button when the user select the item from dropdownlist and click on add button to add to the listbox.

如何防止用户添加稀释物品,并提醒用户在清单箱中已经说出这些物品?

最新资料:

在我的具体设想中,即有一份落户名单,并增列该项目以列入方框,既包括p.net控制,又是增加编码背后的项目,而你的解决办法是纯粹在客户方面,是否有办法阅读清单箱,比较和提醒信息?

最佳回答

相对容易。 有了这一简单标记:

<select id="items">
    <option>One</option>
    <option>Two</option>
    <option>Three</option>
</select>
<input type="button" id="add" value="Add" />
<select id="result" multiple="multiple" size="5">
</select>

这将是 j:

$( #add ).click(function(){
    var item = $( #items ).val();
    var $result = $( #result>option[value="  + item +  "] );
    if($result.length == 0){
        $( #result ).append( <option value="  + item +  ">  + item +  </option> );
    }
    else{
       alert( The item "  + item +  " has already been added );  
    }
});

www.un.org

Edit: 如果你想按照@ryangavin的建议来做,那么,这里是个dle:

问题回答

一种办法是删除该项目,在添加后形成退缩清单,这样用户甚至可以第二次选择。 不再需要警报。





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

热门标签