转到正文

存档

标签: javascript

It's common that you will be very angry when you have to resubmit a form in case of submiting failure.  So, How to resolve it?

Javascript can do this. There is good article[1] for this problem using Javascript. It's very easy for you to read through and you can also get the resouce code from this article. I just spend 20 minutes to resolve this problem. It's very easy!

Good luck for you!

Reference

[1]. http://www.howtocreate.co.uk/tutorials/jsexamples/saveForm.html
[2]. http://www.megasolutions.net/javascript/Saving-form-values-on-submit-in-case-of-failure-75627.aspx

You are not the only one who has difficulty with line breaks in Javascript. I get a lot of questions about it, so hopefully this will help everyone out. If you come from a ColdFusion background, as I do, I think a lot of confusion comes from the fact that line breaks in ColdFusion are represented by the character 13 (new line character) followed by the character 10 (carriage return character)(ex. "#Chr( 13 )##Chr( 10 )#"). After dealing with this for so long, people instinctively try to replace out the same substring in Javascript text: "\n\r".

The problem is that in Javascript, line breaks are represented by the single new line character "\n", not the combination of new line and carriage return. To prove this, let's create a string in Javascript that uses the new line character "\n" to form multiple line:

var strMultiLineText =
	Karen didn't know how to feel any more. She had never liked girls\n" +
	"\"that way,\" but she couldn't ignore the emotion, that surge of \n" +
	"adrenaline that coursed through her body at the sight of Kimmie's\n" +
	"wet, naked, voluptuous figure in the locker room showers.";

... Let's also create a textarea that has this same string, minus the "\n" characters:

继续阅读

When you create a HTML page, and you press "TAB" key, it's very common that you'll select the next control automatically. This is very useful for users.

However, if you have a textarea control, you may want to write "TAB" key to it, but not use the original function of TAB. So you have to write some javascript codes to make this idea work.

Firsly, you must write a textarea control which has a "onkeydown" function:

<input type="text" id="TextBox_InputYourQueries" name="TextBox_InputYourQueries"  onkeydown="return QueriesInputText(event,this);" Text="" />     

   

You must notice that, we return a javascript function in the "onkeydown" event. And our function is :

function QueriesInputText(oEvent,TextObj) {
    var oTextbox = document.getElementById(TextObj.id);
    if (oEvent.keyCode == 9) {
        oTextbox.value += "\t";
        return false;
    }
}

继续阅读

When you write Javascript, you may want to get client id of which as been clicked. for example,  a span link code can be

<span  id="EditEmail" style=" cursor:hand; text-decoration:underline;" onclick="AlertThis()">Click me</span>

you want to call AlertThis() in your javascript which do something task in this span. As we all know, it's very easy that you can pass the explict client id "EditEmail" to the function. Just like:

<span  id="EditEmail" style=" cursor:hand; text-decoration:underline;" onclick="AlertThis('EditEmail')">Click me</span>

and javascript code can be:

function EmailBox(ElementId) {
       var node_hidden = document.getElementById(ElementId);
}

继续阅读

A best way to change the onclikc event with paramter of Javascript is to use code like:

var node = document.getElementById("span_uploadFile");
node.onclick = new Function( "BatchFile_upload('" + HiddenID_name + "')");

the method of passing by many parameters is similar.

Good Luck!

Reference:

1. http://www.chovy.com/web-development/javascript-dynamically-change-onclick-event/
2. http://stackoverflow.com/questions/748941/setattribute-onclick-and-cross-browser-compatability

For some reasons, I want to use javascript to change the text value of asp:Label control.

A very simple solution is that you can get the client id of server control. You can write javascript in .aspx file as follows:

var Hidden = document.getElementById('<%=this.Label_Hidden.ClientID %>');

"Label_Hidden" is the ID name of your asp:Label.  It means that you get the element object of this control. You can see the asp:Label code :

<asp:Label Visible="false" ID="Label_Hidden" runat="server" Text="" ></asp:Label>

However, if you use a externl javascript method , this way will not work.

继续阅读

个人推荐几款优秀的Wordpress插件给大家,这些插件也是我现在一直在用着的:
  • Add Post URL: 可以为日志或页面添加额外的链接。尤其是想加入日志版权信息时,该插件特别有用。
  • Akismet: Wp3.0 默认的垃圾评论判断器,非常棒
  • All in One SEO Pack: 提高博客PR必备
  • Baidu Sitemap Generator: 增加百度收录量。
  • Efficient Related Posts: 可以实现这样的功能:当别人浏览你的日志时,可以推荐相似的其它日志给他
  • Google XML Sitemaps: 提高Google等外国Search Engine收录量
  • Greg's Threaded Comment Numbering: 当别人评论你的日志或页面时,可以嵌套评论
  • HTML-Javascript Adder: 可以边栏上放置Html或JS代码
  • Lc.Archivers: 为你的博客生成一个简明的HTML版本,提高博客PR用
  • Peter's Custom Anti-Spam: 日志评论验证码
  • Post Author: 可以为日志为页面生成作者的相关信息,很适合多用户博客
  • Quotes Collection: 随机显示名人名言,在你的边栏上
  • Simple Tags: Tags功能强大,可以根据你的日志自动生成Tags
  • Syntax Highlighter and Code Prettifier Plugin for WordPress: 如果你是IT民工,这个是必备的。
  • WP-PageNavi: 导航专用,可以生成格式良好的翻页
  • WP-PostViews: 可以统计有多少人看过你的日志和页面
  • wp slug translate: 可以自动将中文日志或页面标题转成英文链接
  • WP-SnapAvatar: 可以在他人评价时自动将对方的网站的快照作为头像,可参考这里

继续阅读

www.liaoqiqi.com网站PR查询 博客简洁版 博客Google_Site_Map 博客Baidu_Site_Map ?