0
我在我的textarea中爲選定的元素添加了標籤,每個標籤都帶有一個id。我將元素存儲在一張桌子上。 但是,我想刪除一些標籤(我必須鍵入「ref」和「point」標籤)。我嘗試這個功能,但是,它不工作:javascript:刪除文本中選定元素的標籤
function deleteTag(textField, tag)
{
var scrollTop = textField.scrollTop; //For the scroll of the text
var start = textField.selectionStart; //beginning of the selected text
var end = textField.selectionEnd; //End of the selected text
var modif=textField.value.substring(start,end); //The text to modify
// Remove the tag
if(modif.match('[^<]'+tag+'id="(\\d+)">') && modif.match('</'+tag+'[>$]'))
{
var regex;
if(tag=="ref")
{
regex=new RegExp('<'+tag+' id="(\\d+)">');
var opt=modif.match(regex)[1];
document.getElementById("refList").remove(opt-1);
}
regex=new RegExp('<'+tag+'[^>]+>');
modif=modif.replace(regex, "");
modif=modif.replace('</'+tag+'>', "");
}
textField.value=textSup+modif+textInf; //We modify the text inside the text area
textField.scrollTop=scrollTop;
}
而且按鈕有這樣的代碼:
<button onclick="deleteTag(textAreaId, 'ref')"> Effacer
通過我在javascript
小提琴將hel pful –
我使用它,但有些時候它不給我一個解決方案 – AbirH