WCF示例代码,键盘上一张下一张兼容IE

复制代码 代码如下:

复制代码 代码如下:

不废话了,直奔主题吧

var sel=document.getElementById(id);//select元素的id
var index=sel.selectedIndex;//获取被选中的option的索引
var textsel= sel.options[index].text;//获取相应的option的内容

< script language = “javascript” >
document.onkeydown = chang_page;
function chang_page(event) {
betway必威亚洲官网,var event = event ? event : (window.event ? window.event : null);
var key = event.keyCode || event.which;
if (key == 37 || key == 33)
location = ”;
if (key == 39 || key == 34)
location = ”;
}
< / script >

wcf端:

您可能感兴趣的文章:

  • Js操作Select大全(取值、设置选中等等)
  • jquery操作select详解(取值,设置选中)
  • jquery中获取select选中值的代码
  • jquery及原生js获取select下拉框选中的值示例
  • jquery控制select的text/value值为选中状态
  • js获取select标签选中值的两种方式
  • js获取select默认选中的Option并不是当前选中值
  • jquery获取select选中值的方法分析
  • jQuery获取select选中的option的value值实现方法
  • jQuery实现select下拉框获取当前选中文本、值、索引

兼容IE,google,firefox的键盘上一张下一张

近几年比较流行restful,为了能让ajax调用,同时也为了支持restful风格的uri,在创建一个Ajax-enabled
Wcf Service后,必须手动修改svc文件,指定Factory,即:

<%@ ServiceHost Language=”C#” Debug=”true”
Service=”ajaxSample.HelloWorld” CodeBehind=”HelloWorld.svc.cs”
Factory=”System.ServiceModel.Activation.WebServiceHostFactory” %>

注:如果不添加Factory,则wcf将无法用类似
的restful方式直接访问。

同时还要去掉web.config中的<enableWebScript />即类似:

<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior
name=”ajaxSample.HelloWorldAspNetAjaxBehavior”>
          <!–<enableWebScript />–>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled=”true”
      multipleSiteBindingsEnabled=”true” />
    <services>
      <service name=”ajaxSample.HelloWorld”>
        <endpoint address=””
behaviorConfiguration=”ajaxSample.HelloWorldAspNetAjaxBehavior”
          binding=”webHttpBinding” contract=”ajaxSample.HelloWorld”
/>
      </service>
    </services>
  </system.serviceModel>

好了,开始写代码,鉴于wcf调用时有GET/POST二种方式,下面把几种常用的情况都写一个示例方法:

复制代码 代码如下:

using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace ajaxSample
{
    [ServiceContract(Namespace = “]
    [AspNetCompatibilityRequirements(RequirementsMode =
AspNetCompatibilityRequirementsMode.Allowed)]
    public class HelloWorld
    {

        /// <summary>
        /// 只能Post的Restful方法
        /// </summary>
        /// <param name=”person”></param>
        /// <param name=”welcome”></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = “POST”, UriTemplate =
“PostRestfulTest/{person}/{welcome}”, ResponseFormat =
WebMessageFormat.Json)]
        public List<string> PostRestfulTest(string person,string
welcome)
        {
            List<string> result = new List<string>();

            result.Add(“PostRestfulTest -> from server:”);
            result.Add(person);
            result.Add(welcome);
            return result;
        }

        /// <summary>
        /// 只能Get的Restful方法
        /// </summary>
        /// <param name=”person”></param>
        /// <param name=”welcome”></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = “GET”, UriTemplate =
“GETRestfulTest/{person}/{welcome}”, ResponseFormat =
WebMessageFormat.Json)]
        public List<string> GETRestfulTest(string person, string
welcome)
        {
            List<string> result = new List<string>();

            result.Add(“GETRestfulTest -> from server:”);
            result.Add(person);
            result.Add(welcome);
            return result;
        }

        /// <summary>
        /// 即可Get与Post的Restful方法
        /// </summary>
        /// <param name=”person”></param>
        /// <param name=”welcome”></param>
        /// <returns></returns>
        [OperationContract]
        [WebInvoke(Method = “*”, UriTemplate =
“RestfulTest/{person}/{welcome}”, ResponseFormat =
WebMessageFormat.Json)]
        public List<string> RestfulTest(string person, string
welcome)
        {
            List<string> result = new List<string>();

            result.Add(“RestfulTest -> from server:”);
            result.Add(person);
            result.Add(welcome);
            return result;
        }

发表评论

电子邮件地址不会被公开。 必填项已用*标注

标签:
网站地图xml地图