我想輸入視頻名稱到文本框,然後按ENTER按鈕,然後瀏覽器播放我存儲在我的磁盤中的視頻。 但我不知道如何獲得HTML視頻src的文本框值。 此鏈接「love.mpe」已修復。我如何使用輸入文本框的值來替換它? 請幫幫我。謝謝。 這裏是我的代碼如何將文本框的值傳遞給HTML和JavaScript中的src鏈接?
<script type="text/javascript">
\t function nhap_so(value)
\t {
\t \t document.getElementById("txtText").value += value;
\t }
\t function clearText()
\t {
\t document.getElementById("txtText").value = "";
\t }
\t function playVideo()
\t {
\t myVideo.play();
\t }
\t function stopVideo()
\t {
\t myVideo.pause();
\t }
\t /*function getValue()
\t {
\t \t var myString = document.getElementById("txtText").value;
\t \t return myString;
\t \t
\t }*/
</script>
<script type="text/javascript" src="demo_getvalue.js"></script>
<body>
<input name="txtText" type="text" id="txtText" size="20" maxlength="10" disabled="disabled"/>
<br />
<br />
<br />
<input type="button" value="1" width="20" height="20" onclick="nhap_so(1);" id="so_1" />
<input type="button" value="2" width="20" height="20" onclick="nhap_so(2);" id="so_2" />
<input type="button" value="3" width="20" height="20" onclick="nhap_so(3);" id="so_3" />
<br />
<input type="button" value="4" width="20" height="20" onclick="nhap_so(4);" id="so_4" />
<input type="button" value="5" width="20" height="20" onclick="nhap_so(5);" id="so_5" />
<input type="button" value="6" width="20" height="20" onclick="nhap_so(6);" id="so_6" />
<br />
<input type="button" value="7" width="20" height="20" onclick="nhap_so(7);" id="so_7" />
<input type="button" value="8" width="20" height="20" onclick="nhap_so(8);" id="so_8" />
<input type="button" value="9" width="20" height="20" onclick="nhap_so(9);" id="so_9" />
<br />
<input type="button" value="0" width="20" height="20" onclick="nhap_so(0);" id="so_0" />
<input type="button" value="ENTER" width="20" height="20" onclick="getValue();"/>
<input type="button" value="CLEAR" width="20" height="20" onclick="clearText();"/>
<br />
<br />
<video id="myVideo" width="640" height="360">
<source src="love.mp4" type="video/mp4">
</video>
<br />
<br />
<input type="button" value="PLAY" width="20" height="20" onclick="playVideo();" />
<input type="button" value="PAUSE" width="20" height="20" onclick="stopVideo();" />
newVal值沒有「.mp4」?它如何工作? – nistelrooy41001662
其簡單。看我編輯了代碼。感謝您指出。 – Mustaghees
感謝您的幫助,但我認爲document.getElementById(「myVideo」)。innerHTML ='