简体   繁体   中英

How do I Parse the HTML Object to a Javascript method as an argument from the C# Code behind

I have a JQuery Javascript function which applies css style attributes to DIV Elements in an HTML Form. The DIVs each contain buttons inside them, so depending on which button you click, the css attributes will be applied to the relevant parent DIV, A variable number of HTML DIVs can exist in the same HTML Form at once.

Here is the JQuery Function:

function ChangeDiv(Sender) {
    $(Sender).closest('Div').css('color', 'red');
}

The code of the DIVs in question is as follows:

<div style="height: 50px; width: 50px;">
    Blah Blah Blah<br />
    Blah Blah Blah<br />
    Blah Blah Blah<br />
    <input type="button" onclick="ChangeDiv(this)" value="change colour" />
</div>

The above code works well with an HTML input control. However I need to use an ASP:Button and inject the JQuery call from my code behind. My Issue is passing the 'Sender' argument with the currently clicked button to the JQuery method.

Your help will be highly appreciated.

尝试在代码背后使用属性OnClientClick:

yourButton.OnClientClick  = "ChangeDiv(this)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM