简体   繁体   English

我该如何修改我的<textarea>&lt;i&gt;html value based on user input&lt;/div&gt;&lt;/i&gt; &lt;b&gt;html 值基于用户输入&lt;/div&gt;&lt;/b&gt;</textarea><div id="text_translate"><p> 我的页面中有一个 html textarea 元素,用户在其中提供逗号分隔值。 例如下面。<br> A-48402,AA,SBAFL,AA+,USD,,</p><p> 从 javascript (我更喜欢)我正在应用逻辑来检查最后一行值是否为空白(仅由逗号分隔)然后放置一个字符串值'Y'。 因此,我正在写以下内容</p><pre>var data = document.getElementById('txid').value; rows = data.split('\n');var row1 = rows[0];row1Values=row1.split(',');</pre><p> 然后我应用逻辑来验证每一行的最后一个值是否为空白,实际上是空白,然后添加以下内容。</p><pre> row_values.push('Y');</pre><p> 它反映在调试器中。</p><p> 但我看到的是 Java 操作 class 中的值“Y”在页面提交时没有反映和显示通常的“Y”。 如何在每一行末尾(有空白的地方)添加这个值'Y',以便它在 class 中可见?</p><pre> String Data = request.getParameter('mbs_inst_data');</pre><p> 该数据填充了相同的空白值。</p></div>

[英]How can I modify my <textarea> html value based on user input

I have a html textarea element in my page where user gives comma separate values.我的页面中有一个 html textarea 元素,用户在其中提供逗号分隔值。 for example below.例如下面。
A-48402,AA,SBAFL,AA+,USD,,

From javascript (which I prefer) I am applying logic to check if the last row value is blank (separated by comma only) then to put a String value 'Y'.从 javascript (我更喜欢)我正在应用逻辑来检查最后一行值是否为空白(仅由逗号分隔)然后放置一个字符串值'Y'。 Thus I am writing the below因此,我正在写以下内容

var data = document.getElementById('txid').value; 
rows = data.split('\n');var row1 = rows[0];row1Values=row1 .split(',');

Then I am applying logic to verify whether the last value for every row is blank or not, which is actually blank, then adding the below.然后我应用逻辑来验证每一行的最后一个值是否为空白,实际上是空白,然后添加以下内容。

row_values.push('Y');

It is reflecting in debugger.它反映在调试器中。

But what I see is the value 'Y' in the Java action class is not reflecting and showing usual 'Y' while the page submit.但我看到的是 Java 操作 class 中的值“Y”在页面提交时没有反映和显示通常的“Y”。 How can I add this value 'Y' in every rows end (where there is blank) so that it will be visible in action class?如何在每一行末尾(有空白的地方)添加这个值'Y',以便它在 class 中可见?

String Data = request.getParameter('mbs_inst_data');

This data is populated with the same blank values.该数据填充了相同的空白值。

You can use it like this.你可以像这样使用它。

<p id="demo">Visit Microsoft! ,,</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  var str = document.getElementById("demo").innerHTML; 
  var res = str.replace(/,,$/, ',Y');
  document.getElementById("demo").innerHTML = res;
}
</script>

Output Output

Visit Microsoft! ,Y

I guess this would help you.我想这会对你有所帮助。

If you're only checking for the last row then the only case that would happen is when it's,, so you can just do a simple check如果你只检查最后一行,那么唯一会发生的情况是它是,所以你可以做一个简单的检查

let data = 'A-48402,AA,SBAFL,AA+,USD,,'
data = data.split(',')
let lastRowIsBlank = data[data.length-2] === ""
// we are doing length - 2 because in your situation we have 2 "" 
// since you have two commas. If you have only 1 comma we would 
// the same steps but with length - 1 
if(lastRowIsBlank) data[data.length-2] = "Y"
return data.toString()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用用户输入修改数组(在 html 中与表格一起显示) - How can I modify array with user input (displayed with table in html) 如何基于我在HTML表单上的用户输入来更新PHP脚本 - How can I update my PHP script based on my user input on HTML form 如何根据用户输入更改html元素的值? - How can I change value of html element based off of user's input? Javascript-我如何突出显示与HTML中的表单用户输入文本区域匹配的元素数组 - Javascript-How Can i Highlight array of elements that matches with form User input textarea in HTML 要修改的jQuery脚本 <p> 标记为HTML,用户在textarea中输入 - jQuery script to modify <p> tag in HTML with user's input in textarea 如何不允许用户继续在 textarea 中输入任何内容? - How can I not allow the user to continue entering any input in textarea? 如何让用户将html输入到文本区域? 如果他们尝试包括在内,我会遇到问题 <textarea> 在文本区域内 - How to let a user input html into a textarea? I have problems if they try to include <textarea> inside a text area 如何以用户身份替换Chrome中textarea的值? - How can I replace the value of a textarea in Chrome as user? 我根据获取的数据创建输入字段,但是如何仅将输入字段作为目标值 - I create input fields based on my fetched data, but how can I only target the input fields with a value 如何使用 node.js 修改我的 HTML 文件? - How can I modify my HTML file with node.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM