2017-08-24 61 views
0

如果我有以下形式...如何插入文本文件內容到textarea?

<form action="upload-script-url" method="post" enctype="multipart/form-data"> 
    <select id="baseText"> 
     <option value="icc2_k_2015_06">ICC2_K-2015.06</option> 
     <option value="icc2_l_2016_03">ICC2_L-2016.03</option> 
     <option value="icc2_m_2016_12" selected >ICC2_M-2016.12</option> 
     <option value="icc2_n_2017_09">ICC2_N-2017.09</option> 
    </select> 
    <br><br> 
    <button type="submit">Retrieve Base Release App Options</button> 
    <br><br> 
</form> 

我怎麼能代替「icc2_ *」以http指向字符串文本文件,並有填充在下面的textarea的選定的文本文件內容...

<div class="textInput"> 
    <h2>Base Release App Options</h2> 
    <textarea id="baseText"></textarea> 
</div> 

我總是收到404未找到錯誤,但我可以通過他們的http:內部地址在新的瀏覽器選項卡中加載文本文件。誰能幫忙?

這裏是一切......

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> 
    <title>jsdifflib demo</title> 
    <link rel="stylesheet" type="text/css" href="diffview.css"/> 
    <script type="text/javascript" src="diffview.js"></script> 
    <script type="text/javascript" src="difflib.js"></script> 
<style type="text/css"> 
body { 
    font-size: 12px; 
    font-family: Sans-Serif; 
} 
h2 { 
    margin: 0.5em 0 0.1em; 
    text-align: center; 
} 
.top { 
    text-align: center; 
} 
.textInput { 
    display: block; 
    width: 49%; 
    float: left; 
} 
textarea { 
    width:100%; 
    height:300px; 
} 
label:hover { 
    text-decoration: underline; 
    cursor: pointer; 
} 
.spacer { 
    margin-left: 10px; 
} 
.viewType { 
    font-size: 16px; 
    clear: both; 
    text-align: center; 
    padding: 1em; 
} 
#diffoutput { 
    width: 100%; 
} 
</style> 

<script type="text/javascript"> 

function diffUsingJS(viewType) { 
    "use strict"; 
    var byId = function (id) { return document.getElementById(id); }, 
     base = difflib.stringAsLines(byId("baseText").value), 
     newtxt = difflib.stringAsLines(byId("newText").value), 
     sm = new difflib.SequenceMatcher(base, newtxt), 
     opcodes = sm.get_opcodes(), 
     diffoutputdiv = byId("diffoutput"), 
     contextSize = byId("contextSize").value; 

    diffoutputdiv.innerHTML = ""; 
    contextSize = contextSize || null; 

    diffoutputdiv.appendChild(diffview.buildView({ 
     baseTextLines: base, 
     newTextLines: newtxt, 
     opcodes: opcodes, 
     baseTextName: "Base Release App Options", 
     newTextName: "New Release App Options", 
     contextSize: contextSize, 
     viewType: viewType 
    })); 
} 

</script> 
</head> 
<body> 
    <h1 class="top"> Check application option settings between releases</h1> 
    <div class="top"> 
    <form action="upload-script-url" method="post" enctype="multipart/form-data"> 
     <select id="baseText"> 
      <option value="icc2_k_2015_06">ICC2_K-2015.06</option> 
      <option value="icc2_l_2016_03">ICC2_L-2016.03</option> 
      <option value="icc2_m_2016_12" selected >ICC2_M-2016.12</option> 
      <option value="icc2_n_2017_09">ICC2_N-2017.09</option> 
     </select> 
     <br><br> 
     <button type="submit">Retrieve Base Release App Options</button> 
     <br><br> 
    </form> 
    <form action="upload-script-url" method="post" enctype="multipart/form-data"> 
     <select id="newText"> 
      <option value="icc2_k_2015_06">ICC2_K-2015.06</option> 
      <option value="icc2_l_2016_03">ICC2_L-2016.03</option> 
      <option value="icc2_m_2016_12">ICC2_M-2016.12</option> 
      <option value="icc2_n_2017_09" selected >ICC2_N-2017.09</option> 
     </select> 
     <br><br> 
     <button type="submit">Retrieve New Release App Options</button> 
     <br><br> 
    </form> 
    </div> 
    <div class="top"> 
     <strong>Context size (optional):</strong> <input type="text" id="contextSize" value=""/> 
    </div> 
    <div class="textInput spacer"> 
     <h2>Base Release App Options</h2> 
     <textarea id="baseText"></textarea> 
    </div> 
    <div class="textInput spacer"> 
     <h2>New Release App Options</h2> 
     <textarea id="newText"></textarea> 
    </div> 
    <div class="viewType"> 
     <input type="radio" name="_viewtype" id="sidebyside" onclick="diffUsingJS(0);" /> <label for="sidebyside">Side by Side Diff</label> 
     &nbsp; &nbsp; 
     <input type="radio" name="_viewtype" id="inline" onclick="diffUsingJS(1);" /> <label for="inline">Inline Diff</label> 
    </div> 
    <div id="diffoutput"> </div> 
</body> 
</html> 

線路是這樣的: -

<option value="icc2_l_2016_03">ICC2_L-2016.03</option> 

... 有效需要這樣做: -

<option value="http://wwwin/myhome/releases/icc2.2016.03.text.file">ICC2_L-2016.03</option> 

.. 。然後textarea id = baseText將會填充icc2.2016.03.text.file的內容。

我搜索了高和低,似乎無法找到我在找什麼。

謝謝!

+1

顯示您的代碼。 – Barmar

+0

你希望看到整個劇本嗎? – Chris

+0

發佈足夠的腳本來重現問題。 – Barmar

回答

0
<textarea style="width:100%;" rows="15" id="list_content"> 
    <?php 
    $filename='../some_ontent.txt'; 
    $size=0; 
    if(file_exists($filename)) 
    { 

     if(file_get_contents($filename)) 
      { 
       if (!$handle = fopen($filename, 'a')) 
        { 
         echo "Temporary server error, sorry for the inconvenience."; 
        } 
        else 
        { 
         //you can add regex here to replace string before echoing the file contents. 
         echo file_get_contents($filename); 
        } 
      } 
    } 
    ?> 
    </textarea> 
+0

嗯......我所看到的只是您在打印到窗口(例如您的原始代碼)上輸入的之間的所有內容。沒有決策權在行使。 – Chris

+0

問題是關於Javascript,這是PHP。 – Barmar

相關問題