简体   繁体   English

我得到输入字符串的格式不正确,尽管我一遍又一遍地使用相同的格式

[英]I am getting Input string was not in a correct format although i used the same format over and over again

Input string was not in a correct format. 输入的字符串格式不正确。 I dont know why, i've used this format before, i guess i'm missing something 我不知道为什么,我以前使用过这种格式,我想我缺少了一些东西

 StringBuilder sb = new StringBuilder(); 

  for (int i = 0; i < 3; i++)
            {
                sb.Append(string.Format(@"
                <button onclick=""playPause{0}()"" type=""button"" >Play/Pause</button> 
                <br> 
                <video id=""video{0}"" width=""420"" controls>
                <source src=""videos/arturo.mp4"" type=""video/mp4"">
                <source src=""videos/arturo.ogg"" type=""video/ogg"">
                Your browser does not support HTML5 video.
                </video>
                <script type=""text/javascript"" > 

                function playPause{0}()
                { 
                var myvideo = document.getElementById('video{0}');
                if (myvideo.paused) 
                myvideo.play(); 
                else 
                myvideo.pause(); 
                } 

                </script> 
   ", i));
  }

            Literal1.Text = sb.ToString();

You need to double the curly braces 您需要将花括号加倍

....
function playPause{0}()
{{ 
var myvideo = document.getElementById('video{0}');
if (myvideo.paused) 
myvideo.play(); 
else 
myvideo.pause(); 
}} 
....

Otherwise the string format interpret them as placeholder for the next argument, that you don't supply in the argument list (It is like you do for the double quotes) 否则,字符串格式会将它们解释为下一个参数的占位符,您不会在参数列表中提供它(就像您对双引号所做的那样)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我使用反应钩子时,API 被一遍又一遍地调用 - API is getting called over and over again when I am using react hooks 我是否在此jQuery代码中一再绑定事件? - Am I binding events over and over again in this jQuery code? 一个简单的 JS 代码,我一遍又一遍地收到相同的结果,我想,我可能犯了一个逻辑错误, - A simple JS code and I am receiving the same result over and over again, I think, I may have done a logical error, 遍历JSON格式的字符串 - Iterate over String of JSON Format 我想在 Google 工作表上找到第一个空列并将数据粘贴到其中,然后一遍又一遍地做同样的事情 - I want to find the first empty column on Google sheet and paste data in it, then do the same thing over and over again 如何将此输入名称转换为正确的标签格式 - how do i turn this input name to the correct label format 格式已弃用警告-但我正在指定格式 - Deprecation warning for format - but I am specifying format 如何在我输入时格式化输入框文本 - how to format input box text as I am typing it 我正在为我的应用程序使用Firebase身份验证。 似乎有一个无限循环,页面不断被重定向 - I am using Firebase authentication for my application. There seems to be an infinite loop where the page keeps being redirected over and over again “未处理FormatException”输入字符串的格式不正确 - “FormatException was unhandled” Input string was not in a correct format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM