gpt4 book ai didi

javascript - 仅包含以数字开头的行

转载 作者:行者123 更新时间:2023-12-04 10:38:08 25 4
gpt4 key购买 nike

我只想包含以序列号开头的行并删除所有其他行。这是我正在尝试的代码,请帮助!请参阅图像以获取更多理解。

图片 :/image/4dVCE.png

提前致谢

Jsfiddle:https://jsfiddle.net/PriyankaJain/gnwhjbyf/

<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<html>
<body>
<h10 style="color: red;">*Write/paste your text, then click on "Convert" button, this will only include sequence number lines and remove all other lines. Now you can copy your text by clicking "Copy Text!" button. You can reset everything by clicking "Clear All!" button.</h10>


<center>
<form>

<textarea autocomplete="off" cols="30" id="TextInput1" name="message" rows="10" style="border: 3px solid #73AD21; width: 40%;"></textarea>

<textarea autocomplete="off" cols="30" id="TextInput2" name="message" rows="10" style="border: 3px solid #73AD21; width: 40%;"></textarea>

<input id="WhiteSpaceRemove" onclick="myFunction()" style="border: 3px solid #73AD21;" type="button" value="Convert" />

<input id="ClearAll" onclick="ClearAllText()" style="border: 3px solid #73AD21;" type="button" value="Clear All!" />

<input id="CopyButton" onclick="CopyFunction()" style="border: 3px solid #73AD21;" type="button" value="Copy Text!" /><br />

</form>
</center>
<script>
function ClearAllText() {
document.getElementById("TextInput1").value = "";
document.getElementById("TextInput2").value = "";
}



function myFunction() {
var x = document.getElementById("TextInput1").value.replace(/\r?\n|\r/g, ", ");
document.getElementById("TextInput2").value.match(/^\d/) = x;
document.getElementById("CopyButton").value="Copy Text!";
}

function CopyFunction() {
var copyText = document.getElementById("TextInput2");
copyText.select();
document.execCommand("copy");

document.getElementById("CopyButton").value="Copied";
}
</script>

</body>
</html>
</div>
<b>Tags: </b></div>
</div>


[1]:

最佳答案

这个可以吗?这主要是你的代码,我只改变了myFunction .

function ClearAllText() {
document.getElementById("TextInput1").value = "";
document.getElementById("TextInput2").value = "";
}

function myFunction() {
const x = document.getElementById("TextInput1").value.replace(/\r?\n|\r/g, '\n');
const lines = x.split('\n');
const numberedLines = lines.filter(line => /^\d/.test(line));
document.getElementById("TextInput2").value = numberedLines.join('\n');
}

function CopyFunction() {
var copyText = document.getElementById("TextInput2");
copyText.select();
document.execCommand("copy");

document.getElementById("CopyButton").value = "Copied";
}
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<html>

<body>
<h10 style="color: red;">*Write/paste your text, then click on "Convert" button, this will only include sequence number lines and remove all other lines. Now you can copy your text by clicking "Copy Text!" button. You can reset everything by clicking "Clear All!" button.</h10>


<center>
<form>

<textarea autocomplete="off" cols="30" id="TextInput1" name="message" rows="10" style="border: 3px solid #73AD21; width: 40%;"></textarea>

<textarea autocomplete="off" cols="30" id="TextInput2" name="message" rows="10" style="border: 3px solid #73AD21; width: 40%;"></textarea>

<input id="WhiteSpaceRemove" onclick="myFunction()" style="border: 3px solid #73AD21;" type="button" value="Convert" />

<input id="ClearAll" onclick="ClearAllText()" style="border: 3px solid #73AD21;" type="button" value="Clear All!" />

<input id="CopyButton" onclick="CopyFunction()" style="border: 3px solid #73AD21;" type="button" value="Copy Text!" /><br />

</form>
</center>

</body>

</html>
</div>
<b>Tags: </b></div>
</div>

关于javascript - 仅包含以数字开头的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60067791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com