Use JavaScript to create powerful GUIs (3)

Source: Internet
Author: User
Create function Insert_link () {
var str = Document.selection.createRange (). text;
Document.my_form.my_textarea.focus ();
var my_link = prompt ("Enter URL:", "http://");
if (My_link!= null) {
var sel = Document.selection.createRange ();
Sel.text = "<a href=\" "+ My_link +" \ ">" + str + "</a>";
}
Return
}
The second function, Insert_link (), is the same as Format_sel (), plus prompt (), which allows the user to enter the value of a hypertext link. Using the results of prompt (), we can combine the selected text and code to create a connection. With these functions, we can create all types of interfaces for the user. Let's take a look at the example below.

using system colors in CSS

The easiest way to use the above function on a Web site is to call these functions in the OnClick event handler of the "bold", "Italic", and "link" buttons, but that's not exciting enough. Since we use the Selection object and limit ourselves to the Ie/win platform, we should take full advantage of IE's features, use user-defined system colors in CSS, and create dynamic buttons like we see in other software. Let's take a look at the style sheet that defines the toolbars, buttons, and the states that are raised and pressed two of buttons.

#toolbar {
margin:0;
padding:0;
width:262px;
Background:buttonface;
border-top:1px solid buttonhighlight;
border-left:1px solid buttonhighlight;
border-bottom:1px solid Buttonshadow;
border-right:1px solid Buttonshadow;
Text-align:right;
}

. button {
Background:buttonface;
border:1px solid buttonface;
Margin:1;
}

. Raised {
border-top:1px solid buttonhighlight;
border-left:1px solid buttonhighlight;
border-bottom:1px solid Buttonshadow;
border-right:1px solid Buttonshadow;
Background:buttonface;
Margin:1;
}

. pressed {
border-top:1px solid Buttonshadow;
border-left:1px solid Buttonshadow;
border-bottom:1px solid buttonhighlight;
border-right:1px solid buttonhighlight;
Background:buttonface;
Margin:1;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.