簡體   English   中英

我得到輸入字符串的格式不正確,盡管我一遍又一遍地使用相同的格式

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

輸入的字符串格式不正確。 我不知道為什么,我以前使用過這種格式,我想我缺少了一些東西

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

否則,字符串格式會將它們解釋為下一個參數的占位符,您不會在參數列表中提供它(就像您對雙引號所做的那樣)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM