【发布时间】:2021-06-01 04:52:58
【问题描述】:
我需要删除文本 Private: in value。
我尝试了以下代码,但它没有删除文本。
请告诉我如何删除它?
现有代码(使用插件创建):
<form method="post" class="dwqa-content-edit-form">
<p>
<input type="text" name="question_title" value="Private: about your question" tabindex="1">
</p>
</form>
我尝试过的代码:
jQuery('.dwqa-content-edit-form p input').text(function () {
return jQuery(this).text().replace(/Private: /g, '');
});
jQuery('.dwqa-content-edit-form p input[type=text]').each(function() {
if (jQuery(this).val() === "Private: ") {
jQuery(this).remove();
}
});
谢谢。
【问题讨论】:
-
.text()应该是.val()第一次尝试。 -
这能回答你的问题吗? How to remove text from a string?
-
嗨斯瓦蒂:谢谢你的帮助:)