Table of Contents
回复讨论(解决方案)
Home Web Front-end HTML Tutorial select 控件的单击事件怎么做_html/css_WEB-ITnose

select 控件的单击事件怎么做_html/css_WEB-ITnose

Jun 21, 2016 am 09:31 AM

select


想要在点击的时候发给服务器一个参数要怎么做

回复讨论(解决方案)

用change事件不行吗  只有发生变化时才发送请求 

用change事件不行吗  只有发生变化时才发送请求 

请来点代码  菜鸟一只

不行  点击了毫无反应

用change事件不行吗  只有发生变化时才发送请求 

看图片怎么感觉楼主用的不是select啊?select的change事件应该是可以的。代码能看看不?

这东西不是select的吧

这东西不是select的吧

是select是JQM上面的用了框架  

看图片怎么感觉楼主用的不是select啊?select的change事件应该是可以的。代码能看看不?


这是控件的代码 


                    
                


单击事件已经做出来了 但是用这个运行服务器端的代码会导致服务器端的代码运行顺序发生问题 运行出来的程序不会报错,能运行  但功能有时候能实现有时候不能实现

这是完整的JS代码

<script> <br /> //定义一个函数用以显示当前时间 <br /> <br /> function ms() { <br /> loms(); <br /> displayTime(); <br /> } <br /> <br /> function displayTime() { <br /> var elt = document.getElementById("falsh"); <br /> var now = new Date(); <br /> elt.innerHTML = now.toLocaleTimeString(); <br /> setTimeout(displayTime,1000); <br /> callServer(); <br /> <br /> } <br /> function ajaxRomex(){ <br /> if (window.ActiveXObject) { <br /> return new ActiveXObject("Microsoft.XMLHTTP"); <br /> } else if (window.XMLHttpRequest) { <br /> return new XMLHttpRequest(); <br /> } <br /> <br /> } <br /> var xhr; <br /> var url; <br /> function callServer() { <br /> <br /> url = "Default.aspx?_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.onreadystatechange = updatePage; <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> <br /> } <br /> <br /> function updatePage() { <br /> if (xhr.readyState == 4 && xhr.status == 200) { <br /> var dom = xhr.responseXML; <br /> document.getElementById("s1").value = dom.getElementsByTagName("Temperature")[0].firstChild.nodeValue+"℃"; <br /> document.getElementById("s2").value = dom.getElementsByTagName("Humidity")[0].firstChild.nodeValue+"%"; <br /> document.getElementById("s3").value = dom.getElementsByTagName("Airquality")[0].firstChild.nodeValue+"级"; <br /> document.getElementById("s4").value = dom.getElementsByTagName("Fan")[0].firstChild.nodeValue == 0 ? "开" : "关"; <br /> } <br /> } <br /> window.onload = ms; <br /> function loms(){ <br /> $("#toggleswitch2").change(function () { <br /> url = "Default.aspx?bu=Button1&_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> }); <br /> $("#toggleswitch3").change(function () { <br /> url = "Default.aspx?bu=Button2&_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> }); <br /> $("#toggleswitch4").change(function () { <br /> url = "Default.aspx?bu=Button3&_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> }); <br /> $("#toggleswitch5").change(function () { <br /> url = "Default.aspx?bu=Button4&_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> }); <br /> $("#toggleswitch6").change(function () { <br /> url = "Default.aspx?bu=Button5&_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> }); <br /> $("#toggleswitch7").change(function () { <br /> url = "Default.aspx?bu=Button6&_" + new Date().getTime(); <br /> xhr = ajaxRomex(); <br /> xhr.open("GET", url, true); <br /> xhr.send(null); <br /> }); <br /> } <br /> <br /> </script>


接下来是完整的服务器端代码

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "text/xml";
        Response.Charset = "UTF-8";
        string db = "Data Source=LENOVO-85DD1539;Initial Catalog=Emne;User ID=sa;Password=ehs123456";
            string sql = "select * from Emne";
            SqlConnection conn = new SqlConnection(db);
            conn.Open();
            SqlCommand comm = new SqlCommand(sql, conn);
            SqlDataReader sdr = comm.ExecuteReader();
            Class1 c = new Class1();
            while (sdr.Read())
            {
                c.Id = Convert.ToInt32(sdr["Id"]);
                c.Temperature = Convert.ToInt32(sdr["Temperature"]);
                c.Humidity = Convert.ToInt32(sdr["Humidity"]);
                c.Airquality = Convert.ToInt32(sdr["Airquality"]);
                c.Fan = Convert.ToInt32(sdr["Fan"]);
                c.Button1 = Convert.ToInt32(sdr["Button1"]);
                c.Button2 = Convert.ToInt32(sdr["Button2"]);
                c.Button3 = Convert.ToInt32(sdr["Button3"]);
                c.Button4 = Convert.ToInt32(sdr["Button4"]);
                c.Button5 = Convert.ToInt32(sdr["Button5"]);
                c.Button6 = Convert.ToInt32(sdr["Button6"]);
            }
            XmlWriter writer = null;
            try
            {
                XmlSerializer serializer = new XmlSerializer(c.GetType());
                //string l = AppDomain.CurrentDomain.BaseDirectory;
                //StreamWriter myWriter = new StreamWriter(l + "/myFileName.xml");
                //mySerializer.Serialize(myWriter, c);
                writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
                serializer.Serialize(writer, c);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
            }
            if (Request.QueryString["bu"] != null)
            {
                try
                {
                    string id = Request.QueryString["bu"].ToString();

                    if (id.Equals("Button1"))
                    {
                        if (c.Button1 == 0)
                        {
                            sql = "update Emne set Button1=1 where Id=" + c.Id;
                        }
                        else
                        {
                            sql = "update Emne set Button1=0 where Id=" + c.Id;
                        }
                        conn.Close();
                        conn.Open();
                        comm = new SqlCommand(sql, conn);
                        comm.ExecuteReader();
                        conn.Close();
                    }
                    if (id.Equals("Button2"))
                    {
                        if (c.Button1 == 0)
                        {
                            sql = "update Emne set Button2=1 where Id=" + c.Id;
                        }
                        else
                        {
                            sql = "update Emne set Button2=0 where Id=" + c.Id;
                        }
                        conn.Close();
                        conn.Open();
                        comm = new SqlCommand(sql, conn);
                        comm.ExecuteReader();
                        conn.Close();
                    }
                    if (id.Equals("Button3"))
                    {
                        if (c.Button1 == 0)
                        {
                            sql = "update Emne set Button3=1 where Id=" + c.Id;
                        }
                        else
                        {
                            sql = "update Emne set Button3=0 where Id=" + c.Id;
                        }
                        conn.Close();
                        conn.Open();
                        comm = new SqlCommand(sql, conn);
                        comm.ExecuteReader();
                        conn.Close();
                    }
                    if (id.Equals("Button4"))
                    {
                        if (c.Button1 == 0)
                        {
                            sql = "update Emne set Button4=1 where Id=" + c.Id;
                        }
                        else
                        {
                            sql = "update Emne set Button4=0 where Id=" + c.Id;
                        }
                        conn.Close();
                        conn.Open();
                        comm = new SqlCommand(sql, conn);
                        comm.ExecuteReader();
                        conn.Close();
                    }
                    if (id.Equals("Button5"))
                    {
                        if (c.Button1 == 0)
                        {
                            sql = "update Emne set Button5=1 where Id=" + c.Id;
                        }
                        else
                        {
                            sql = "update Emne set Button5=0 where Id=" + c.Id;
                        }
                        conn.Close();
                        conn.Open();
                        comm = new SqlCommand(sql, conn);
                        comm.ExecuteReader();
                        conn.Close();
                    }
                    if (id.Equals("Button6"))
                    {
                        if (c.Button1 == 0)
                        {
                            sql = "update Emne set Button6=1 where Id=" + c.Id;
                        }
                        else
                        {
                            sql = "update Emne set Button6=0 where Id=" + c.Id;
                        }
                        conn.Close();
                        conn.Open();
                        comm = new SqlCommand(sql, conn);
                        comm.ExecuteReader();
                        conn.Close();
                    }
                }
                finally
                {
                }
                
                
                
            }

    }
}

求大神帮忙看一下BUG出在哪里
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML: Building the Structure of Web Pages HTML: Building the Structure of Web Pages Apr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

The Role of HTML: Structuring Web Content The Role of HTML: Structuring Web Content Apr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

See all articles