Can I stop .NET eating IDs?

前端 未结 10 1495
我寻月下人不归
我寻月下人不归 2020-12-16 11:35

I\'m an Information Architect and JavaScript developer by trade nowadays, but recently I\'ve been getting back into back-end coding again. And, whilst trying to get an HTML

10条回答
  •  天命终不由人
    2020-12-16 11:54

    What I usually do is create a general function that receives the name of the field. It adds the usual "asp.net" prefix and returns the object.

    var elemPrefix = 'ctl00-ContentPlaceHolder-'; //replace the dashes for underscores
    
    var o = function(name)
    {    
        return document.getElementById(elemPrefix + name)
    }
    

    With that you can use this kind of calls in jQuery

    $(o('buttonId')).bind('click', function() { alert('hi); });
    

提交回复
热议问题