小编Jsp*_*o30的帖子

选择所有文本,然后将其复制到javascript中

我有一个代码,如果我选择了一些文本然后单击“复制”,它将起作用。

我的问题是,如果我不选择任何文本并单击,copy则必须复制所有文本。

我的HTML:

<textarea id="txt" style="width:100%;height:100px;">To enjoy good health</textarea>

<div align="center"><button class="btn-md">copy</button></div>
Run Code Online (Sandbox Code Playgroud)

我的剧本:

$(document).ready(function(){
   $('.btn-md').click(function(){
     $('#txt').focus();
     document.execCommand('copy');
   });
});
Run Code Online (Sandbox Code Playgroud)

javascript jquery

3
推荐指数
1
解决办法
2045
查看次数

ArgumentNullException:未将字符串引用设置为字符串的实例。参数名称:s System.Text.Encoding.GetBytes(string s)

我有这个方法来生成令牌:

[HttpPost("login")]
        public async Task<IActionResult> login(UserForLoginDto userForLoginDto)
        {
            var userFromRepo = await _repo.Login(userForLoginDto.Username.ToLower(), userForLoginDto.Password);

            if(userFromRepo == null)
               return Unauthorized();

            var claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, userFromRepo.Id.ToString()),
                new Claim(ClaimTypes.Name, userFromRepo.Username)
            };   

            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.GetSection("AppSettings:Token").Value));

            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(claims),
                Expires = DateTime.Now.AddDays(1),
                SigningCredentials = creds
            };

            var tokenHandler = new JwtSecurityTokenHandler();

            var token = tokenHandler.CreateToken(tokenDescriptor);

            return Ok(new{
                token = tokenHandler.WriteToken(token)
            });

        }
Run Code Online (Sandbox Code Playgroud)

当我通过邮递员调用此 API 时:

本地主机:5000/api/auth/登录

在正文中用户名:“john”,密码:“password” …

asp.net-core

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

javascript ×1

jquery ×1