方式一
<textarea id="textarea_innerpropersonalidentity_check_1_ids_items_B20911000B0001@@C" class = "textarea_personal" name="SH_JL" rows="5" cols="5"></textarea>
js结果:
var personal_id = $($(".textarea_personal")).attr("id");
var new_personal_id = personal_id.replace(/@/g,"\\@");
var shJL=$("#"+new_personal_id).val();//最终结果
使用说明:
①在textarea中添加以下属性:
id="textarea_innerpropersonalidentity_check_1_ids_items_B20911000B0001@@C" class = "textarea_personal"
②直接使用上面的js就能够获取
方式二
<textarea id="txArea"></textarea> <button id="btn" onclick="toPage()"> 提交</button>
function toPage(){ var tx = document.getElementById("txArea").value;使用value属性就可以获取到值 alert(tx.length+":::"+tx);//如果没有值得时候,长度为0,不存在null的情况 }
本文介绍了两种在JavaScript中获取textarea元素值的方法。第一种适用于包含特殊字符ID的textarea,通过正则表达式处理ID来获取值;第二种则是常规方法,直接通过getElementById获取元素并读取其值。
132

被折叠的 条评论
为什么被折叠?



