输入的字符串格式不正确。我不知道为什么,我以前使用过这种格式,我想我缺少了一些东西

 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();

最佳答案

您需要将花括号加倍

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


否则,字符串格式会将它们解释为下一个参数的占位符,您不会在参数列表中提供它(就像您对双引号所做的那样)

10-08 17:50