如何将文本文件内容插入textarea?

时间:2017-08-24 03:09:17

标签: jquery html

如果我有以下表格......

graph.links.forEach(function(d) {
      linkedByIndex[d.source.index + "," + d.target.index] = 1;
      linkedByIndex[d.target.index + "," + d.source.index] = 1;
    });
function neighboring(a, b) {
    return a.index == b.index ||  linkedByIndex[a.index + "," + b.index];
}

如何更换" icc2 _ *"带有http指针到文本文件的字符串,并在下面的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>

我一直收到404 Not Found错误,但我可以通过他们的http:内部地址在新的浏览器选项卡中加载文本文件。有人可以帮忙吗?

这就是一切......

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

这样的行: -

<!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>

...然后textarea id = baseText将填充icc2.2016.03.text.file的内容。

我搜索过高低,似乎找不到我要找的东西。

谢谢!

1 个答案:

答案 0 :(得分: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>