代码背后的javascript [英] javascript under code behind

查看:117
本文介绍了代码背后的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我在TextBox文本更改事件中调用此JS

 <   script     type   =  text / javascript >  
Sys.Application。 add_load( function (){
var t = document .getElementById(' scrollable-content');
t。 scrollTop = t.scrollHeight;
});
< / script >

解决方案

我假设您知道如何加载jquery /在哪里获取jquery。但下面是两个选项......一个javascript方式(在变化时)和一个jquery方法来做你想要的(或者我认为你在问什么)。



 1)使用Jquery 

< script type = < span class =code-keyword> text / javascript >


(#textbox) .keyup(function(){
var t = document.getElementById('scrollable-content');
t.scrollTop = t.scrollHeight;
});
< / script >


< div id = scrollable-content >

< / div >

< 输入 type = text id = textbox / >


2)使用javascript

< script < span class =code-attribute> type = text / javascript >
Sys.Application.add_load(function(){
var t = document.getElementById('scrollable-content');
t.scrollTop = t.scrollHeight;
});
< / script >


< div id = scrollable-content >

< / div >

< 输入 type = text onchange = Sys.Application.add_load / >


仅当你的文本框是asp.net文本框时才适用,如果是,那么:



假设这是.aspx中的文本框:

< asp:TextBox ID =TextBox1runat =server>< / asp:TextBox> 



然后将你的js代码包装成如下的js函数:

 <  < span class =code-leadattribute> script     type   =  text / javascript >  
function changeHeight( ){
var t = document.getElementById('scrollable-content');
t.scrollTop = t.scrollHeight;
}
< / script >



确保在页面的标题部分下添加此脚本部分...

然后去到代码后面的asp.net页面'page_load事件并添加如下代码:

  if (!Page.IsPostBack)
TextBox1.Attributes.Add( onchange javascript:changeHeight(););



完成,构建并运行你的应用程序并让我知道这是你想要做的......


Please help me to call this JS in a TextBox text changed event

<script type="text/javascript">
Sys.Application.add_load(function() {
var t = document.getElementById('scrollable-content');
t.scrollTop = t.scrollHeight;
});
</script>

解决方案

I am making the assumption that you know how to load jquery/where to get jquery. But below are two options...a "javascript" way (on change) and a jquery method of doing what you are asking (or what i think you are asking).

1) Using Jquery

<script type="text/javascript">


("#textbox").keyup(function(){ var t = document.getElementById('scrollable-content'); t.scrollTop = t.scrollHeight; }); </script> <div id="scrollable-content"> </div> <input type="text" id="textbox" /> 2) Using javascript <script type="text/javascript"> Sys.Application.add_load(function() { var t = document.getElementById('scrollable-content'); t.scrollTop = t.scrollHeight; }); </script> <div id="scrollable-content"> </div> <input type="text" onchange="Sys.Application.add_load" />


This applies, only if your textbox is asp.net textbox, if so then:

assume this is your text box in .aspx:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>


then just wrap your js code into a js function like below:

<script type="text/javascript">
function changeHeight() {
var t = document.getElementById('scrollable-content');
t.scrollTop = t.scrollHeight;
}
</script>


Make sure to add this script part under your page''s heade section...
then go to your asp.net page''s page_load event in code behind side and add code like this:

if(!Page.IsPostBack)
TextBox1.Attributes.Add("onchange", "javascript:changeHeight();");


done, build and run your app and let me know if this is what you wanted to do...


这篇关于代码背后的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆