在DropDownList SelectedIndexChanged事件上调用JavaScript函数 [英] Call JavaScript function on DropDownList SelectedIndexChanged Event
本文介绍了在DropDownList SelectedIndexChanged事件上调用JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个java脚本:
< script type = text / javascript>
function mycarousel_initCallback(carousel){
// 如果用户单击上一个或下一个按钮,则禁用自动滚动。
carousel.buttonNext.bind(' < span class =code-string> click', function (){
carousel.startAuto( 0 );
});
carousel.buttonPrev.bind(' click', function (){
carousel.startAuto( 0 );
});
// 如果用户将光标移动到剪辑上,则暂停自动滚动。
carousel.clip.hover( function (){
carousel.stopAuto();
}, function (){
carousel.startAuto();
});
};
jQuery( document )。ready( function (){
jQuery(' #mycarousel')。jcarousel({
auto: 2 ,
wrap:' last',
initCallback:mycarousel_initCallback
});
});
< / script>
这个java脚本放在母版页中,我想调用它下拉选择索引中的java脚本已更改,下拉列表放在用户控件中所以我该怎么做才能帮助我
解决方案
嗨Arun,
尝试使用Response.Write()方法,但在此之前请确保在输出HTML中正确引用了JS文件。
Response.Write( < script> mycarousel_initCallback(carousel);< ; / script>);
希望这会有所帮助。
快乐编码:)
在你的代码背后写如下。
受保护 void Page_Load(< span class =code-keyword> object se nder,EventArgs e)
{
ddl.SelectedIndexChanged + = new EventHandler(ddl_SelectedIndexChanged);
if (!Page.IsPostBack)
{
ddl.Attributes.Add( onchange, mycarousel_initCallback(ddl );跨度>);
}
}
受保护 void ddl_SelectedIndexChanged( object sender,EventArgs e)
{
// 您的代码
}
您的ASPX将如下:
< asp:DropDownList ID = ddl runat = server AutoPostBack = true >
< asp: ListItem 文字 = a 值 = a > < / asp:ListItem >
< asp:ListItem 文本 = b 值 = b > < / asp:ListItem >
< / asp:DropDownList >
您也可以这样做:
您可以添加onchange = yourfunctionname()
下拉列表中的代码并添加函数在开头的脚本标签中。
这是最好的办法...
感谢
I have a java script:
<script type="text/javascript">
function mycarousel_initCallback(carousel) {
// Disable autoscrolling if the user clicks the prev or next button.
carousel.buttonNext.bind('click', function () {
carousel.startAuto(0);
});
carousel.buttonPrev.bind('click', function () {
carousel.startAuto(0);
});
// Pause autoscrolling if the user moves with the cursor over the clip.
carousel.clip.hover(function () {
carousel.stopAuto();
}, function () {
carousel.startAuto();
});
};
jQuery(document).ready(function () {
jQuery('#mycarousel').jcarousel({
auto: 2,
wrap: 'last',
initCallback: mycarousel_initCallback
});
});
</script>
This java script is put in master page and i want to call this java script in drop down selected index changed, dropdown is placed in user control So how can i do this plz help me
解决方案
Hi Arun,
Try using Response.Write() method for this but before this please ensure that the JS file is referenced properly in the output HTML.
Response.Write("<script>mycarousel_initCallback(carousel);</script>");
Hope this helps.
Happy Coding :)
In your code behind write as below.
protected void Page_Load(object sender, EventArgs e) { ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged); if (!Page.IsPostBack) { ddl.Attributes.Add("onchange", "mycarousel_initCallback(ddl);"); } } protected void ddl_SelectedIndexChanged(object sender, EventArgs e) { //Your Code }
And your ASPX will be like:
<asp:DropDownList ID="ddl" runat="server" AutoPostBack="true"> <asp:ListItem Text="a" Value="a"></asp:ListItem> <asp:ListItem Text="b" Value="b"></asp:ListItem> </asp:DropDownList>
Hi,
You can also do like this:
You can add theonchange="yourfunctionname()"code to the dropdown and add the function in the script tag in the begining.
This is the best way to do...
Thanks
这篇关于在DropDownList SelectedIndexChanged事件上调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文