Go language uses Go-sciter to create desktop Apps (ii) UI elements find, add, delete, modify

Source: Internet
Author: User

We can use Go-sciter to provide us with the method, convenient to Html,css written UI interface for the enhancement and deletion of the search.

The Demo3.go code is as follows:

Package Main;import ("Github.com/sciter-sdk/go-sciter" "Github.com/sciter-sdk/go-sciter/window" "Log" "FMT")// Some basic operation func base (Root *sciter. Element) {//SELECT elements by ID UL, _: = root. Selectbyid ("list");//Gets the text of the element, _: = ul. Text (); fmt. Println ("Text:", text);//Gets the element's html//parameter to True, then returns the element outside the html//parameter is false, returns the element inside HTMLText, _ = ul. Html (false); Fmt. PRINTLN ("HTML:", text);//Gets the number of child elements N, _: = ul. Childrencount (); fmt. PRINTLN (n);} Dynamic add element func addelement (root *sciter. Element) {//Create a component Add, _: = Sciter. createelement ("Li", "444");//Set the attribute of the element Add. SetAttr ("Data", "add");//select elements by tag and ID, similar to Jqueryul, _: = root. Selectfirst ("ul#list");//Insert element, subscript starting from 0 err: = ul. Insert (add, 3); if err! = Nil {log. Fatal ("add element Failed");} Add2, _: = Sciter. createelement ("Li", ""); ERR2: = ul. Insert (ADD2, 4);//note here, the element is first insert before you set the HTML to be valid//set to add the htmladd2 of the element. Sethtml ("<a href= ' http://www.baidu.com ' >555</a>", Sciter. sih_replace_content); if err2! = Nil {log. Fatal ("add element Failed");}} remove element func delelement (root *sciter. Element) {ul, _: = root. Selectfirst ("ul#list");//Get First childelement, subscript starting from 0 Li, _: = ul. Nthchild (0);//delete element li. Delete ();//We can also use the CSS selector to directly select the element to delete//note that the Nth-child (n) subscript in the CSS starts from 1 li2, _: = root. Selectfirst ("Ul#list>li:nth-child (2)");//delete element Li2. Delete ();} Modifies the element func updelement (root *sciter. Element) {Li, _: = root. Selectfirst ("Ul#list>li:nth-child (1)");//Set the style li for the element. SetStyle ("Color", "#f00");//Set html//parameter one for element: HTML content//Parameter two: where HTML is placed, sih_replace_content means replace old content li.sethtml ("<a href = ' http://www.baidu.com ' >baidu.com</a> ', Sciter. sih_replace_content);//append content Li to the last side. sethtml ("haha", sciter. Sih_append_after_last);//Set element properties Li. SetAttr ("Test", "Test"); Li2, _: = root. Selectfirst ("Ul#list>li:nth-child (2)");//Set Text Li2. SetText ("I Change my Change");} Find element func selelement (root *sciter. Element) {//select elements via CSS selector, return *element's Sliceroot.select ("Ul#list>li");//return the first element through the selector//is also a call to select, Only the first element of root is returned. Selectfirst ("Ul#list>li");//through Element Idroot.selectbyid ("list");//select parent element//Parameter two: indicates depth root. Selectparent ("Li", 1);//Returns the selector matches a unique child element, and if none or more matches, it throws Panicroot.selectunique ("Ul#list>li:nth-child (1)");} Func mAin () {///Create a new window///This is the default value used by parameter I and parameter two//defaultwindowcreateflag = Sw_titlebar | sw_resizeable | Sw_controls | Sw_main | Sw_enable_debug//defaultrect = &rect{0, 0, 400}w, err: = window. New (Sciter. Defaultwindowcreateflag, Sciter. Defaultrect); if err! = Nil {log. Fatal (err);} Set the title W. Settitle ("text HTML"); HTML: = ' 

Go language uses Go-sciter to create desktop Apps (ii) UI elements find, add, delete, modify

Related Article

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.